javax.imageio

Read byte array into buffered image WITHOUT ImageIO

送分小仙女□ 提交于 2020-01-15 12:16:08
问题 I have a code that turns a byte array into BufferedImage using ImageIO. public void readImage(byte[] imageBytes) { ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes); BufferedImage bufferedImage = null; try { bufferedImage = ImageIO.read(inputStream); } catch (Exception e) { e.printStackTrace(); } // do something with bufferedImage } But I found that for certain jpeg images, it throws a CMMException, every time. Here's the stack trace: java.awt.color.CMMException: Cannot

Read byte array into buffered image WITHOUT ImageIO

删除回忆录丶 提交于 2020-01-15 12:16:07
问题 I have a code that turns a byte array into BufferedImage using ImageIO. public void readImage(byte[] imageBytes) { ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes); BufferedImage bufferedImage = null; try { bufferedImage = ImageIO.read(inputStream); } catch (Exception e) { e.printStackTrace(); } // do something with bufferedImage } But I found that for certain jpeg images, it throws a CMMException, every time. Here's the stack trace: java.awt.color.CMMException: Cannot

How to change the image type of a BufferedImage which is loaded from file?

谁说我不能喝 提交于 2020-01-15 06:21:07
问题 I'm trying to access the pixels in a BufferedImage which is loaded from a file using ImageIO.read(filePath) , but I get this error : Exception in thread "Game" java.lang.ClassCastException: java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt at com.package.graphics.Texture.<init>(Texture.java:29) at com.package.graphics.Texture.loadTexture(Texture.java:40) at com.package.Game.run(Game.java:71) at java.lang.Thread.run(Unknown Source) In the code, the line which the

Reading JPEGs in Java

不问归期 提交于 2020-01-14 09:59:08
问题 I'm attempting to get a JPEG into a BufferedImage to display on a JPanel . However, javax.imageio.ImageIO.read() seems to be very fussy about the JPEGs it processes, often throwing an IIOException . The same JPEGs open fine in pretty much any image reader you'd care to name. I've looked at Apache's Sanselan and JAI. But Sanselan can't process JPEGs and JAI isn't available for 64-bit Windows platforms and doesn't seem to be maintained (the last update was in 2006). A previous answer on

Java read different type of image formats jpg,tif,gif,png

旧巷老猫 提交于 2020-01-12 10:46:39
问题 I am trying to read some image files jpg, tif, gif, png and need to save files and create icons. And i am getting UnsupportedTypeException . ImageIO.read(file); If i use following line, as earlier discuss in form. BufferedImage img = JPEGCodec.createJPEGDecoder(inputStream).decodeAsBufferedImage(); I get JPEGCodec cannot found symbol. I am using netbean 7.0.1. I have also added jai-imageio.jar. 回答1: By default, ImageIO can only read JPG, GIF and PNG file formats, if I remember right. To add

ImageIO.read( ) always rotates my uploaded picture

冷暖自知 提交于 2020-01-12 04:52:34
问题 I want to create a web application that allow users to upload their image to the server. When they click send, their image will be uploaded to the server (multipart). Before saving, I want to make some operation with the image, so I decided to use .. ImageIO.read(InputStream) to get BufferedImage object here is the code: public static BufferedImage getBufferedImageFromMultipartFile(MultipartFile file) throws APIException { BufferedImage bi = null; try { bi = ImageIO.read(file.getInputStream()

IllegalArgumentException: Numbers of source Raster bands and source color space components do not match For a color image Exception

青春壹個敷衍的年華 提交于 2020-01-10 10:15:32
问题 The above answer that someone has suggest, converts my colored image to a black and white one. So it's not appropriate for my question. File file = new File("path"); BufferedImage bufferedImage = ImageIO.read( file ); here is the code and below is the image. Download the image and save in your pc. And try to run the above code with a correct value of path, it will throw an exception in the topic Download image: https://skydrive.live.com/?cid=19547371C4F3B839&id=19547371C4F3B839%21105 Simply

Manipulate an image without deleting its EXIF data

一个人想着一个人 提交于 2020-01-09 09:09:42
问题 Using imageIO, I usually have the problem of transforming an image file, and after overwriting it, it loses all of its EXIF data. Is there any way to preserve it without first extracting it, caching it, and then resetting it? 回答1: ImageIO do have this functionality itself, but instead of ImageIO.read you will need to use ImageReader: ImageReader reader = ImageIO.getImageReadersBySuffix("jpg").next(); (you may want to also check if such reader exists). Then you need to set the input: reader

How to make a simple screenshot method using LWJGL?

房东的猫 提交于 2020-01-06 07:55:41
问题 So basically I was messing about with LWJGL for a while now, and I came to a sudden stop with with annoyances surrounding glReadPixels() . And why it will only read from left-bottom -> top-right. So I am here to answer my own question since I figured all this stuff out, And I am hoping my discoveries might be of some use to someone else. As a side-note I am using: glOrtho(0, WIDTH, 0 , HEIGHT, 1, -1); 回答1: So here it is my screen-capture code which can be implemented in any LWJGL application

Save a GIF with index transparency using ImageIO out of an image with alpha transparency

怎甘沉沦 提交于 2020-01-05 07:04:17
问题 I have a BufferedImage with alpha transparency, which I need to save as GIF with index transparency. There are no semi-opague pixels, therefore a conversion should be possible. Using the code found under http://gman.eichberger.de/2007/07/transparent-gifs-in-java.html, I define a transparency color (green, for instance, which is not part of the current image) and make it transparent. Works fine, BUT it mixes up the color table and all the colors look awful (although I only use 3 different