Skip to content

Instantly share code, notes, and snippets.

@ricardolee
Created September 7, 2016 00:53
Show Gist options
  • Save ricardolee/b680e50531c66bbf862ace7d41981fc5 to your computer and use it in GitHub Desktop.
Save ricardolee/b680e50531c66bbf862ace7d41981fc5 to your computer and use it in GitHub Desktop.
ImageTest
package local;
import org.junit.Test;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Iterator;
/**
* @author Li Pengcheng
* Create on 8/26/16
*/
public class ImageTest {
static String TEST_DIR = "/Users/lee/Downloads/test";
static String IMAGE_NAME = "testD.jpg";
static String OUTPUT_FILE = "test.jpg";
@Test
public void testImage() throws Exception {
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
while (readers.hasNext()) {
System.out.println("reader: " + readers.next());
}
byte[] dates = Files.readAllBytes(Paths.get(TEST_DIR + "/" + IMAGE_NAME));
// byte[] bytesEncoded = Base64.encodeBase64(dates);
// dates = Base64.decodeBase64(bytesEncoded);
// BufferedImage bufferedImage = ImageUtils.toBufferedImage(dates);
BufferedImage bufferedImage2 = ImageIO.read(new ByteArrayInputStream(dates));
ImageIO.write(bufferedImage2, "jpg" , new FileOutputStream(TEST_DIR + "/" + OUTPUT_FILE));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment