Created
September 7, 2016 00:53
-
-
Save ricardolee/b680e50531c66bbf862ace7d41981fc5 to your computer and use it in GitHub Desktop.
ImageTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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