javax.imageio

Java 1.5.0_16 corrupted colours when saving jpg image

血红的双手。 提交于 2019-12-10 17:25:09
问题 i have a loaded image from disk (stored as a BufferedImage ), which i display correctly on a JPanel but when i try to re-save this image using the command below, the image is saved in a reddish hue. ImageIO.write(image, "jpg", fileName); Note! image is a BufferedImage and fileName is a File object pointing to the filename that will be saved which end in " .jpg ". I have read that there were problems with ImageIO methods in earlier JDKs but i'm not on one of those versions as far as i could

ImageIO.write not saving out as gif, but works for jpgs and pngs?

喜你入骨 提交于 2019-12-10 17:25:07
问题 I suspect the solution here is probably really simple, but I'm stumped... // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB); // fill image data (works fine) ImageIO.write(bufferedImage, "JPG", f1); // works fine ImageIO.write(bufferedImage, "PNG", f2); // works fine ImageIO.write(bufferedImage, "GIF", f3); // this returns false, creates a broken gif file, but fires no exceptions Does ImageIO.write() not work for gifs? is this some

Can I tell what the file type of a BufferedImage originally was?

假如想象 提交于 2019-12-10 13:22:31
问题 In my code, I have a BufferedImage that was loaded with the ImageIO class like so: BufferedImage image = ImageIO.read(new File (filePath); Later on, I want to save it to a byte array, but the ImageIO.write method requires me to pick either a GIF, PNG, or JPG format to write my image as (as described in the tutorial here). I want to pick the same file type as the original image. If the image was originally a GIF, I don't want the extra overhead of saving it as a PNG. But if the image was

With “ImageIO.write()” API call I get NullPointerException

∥☆過路亽.° 提交于 2019-12-10 02:46:51
问题 With ImageIO.write() API call, I get NullPointerException when I pass a non-existent path like "\\abc\abc.png" . I pass the non-existent path purposely to test something but instead of getting FileNotFoundException , I get NPE . Why is that? ImageIO.write() API is supposed to throw IOException but don't why I get NPE . I use exception message string to show it in a message box to user but in this case NPE.getLocalizedMessage() returns empty string and hence the popup is empty with just an

Invalid PNG Image file: iDOT doesn't point to valid IDAT chunk

房东的猫 提交于 2019-12-09 08:41:02
问题 I have some HTML content pages in an app and I'm using a UIWebView to display them. Some of these pages have a PNG image in them that is generating the following message in the debug console in xcode: ImageIO: PNG invalid PNG file: iDOT doesn't point to valid IDAT chunk The image still displays and looks correct. Also this only happens when I run the app on an iPad (3rd generation). My iPhone 4 doesn't display this message. My first thought was that it was caused by a ~ character in the

How to exclude specific TIFF reader from ImageIO?

半城伤御伤魂 提交于 2019-12-09 03:21:16
问题 Stack: Java - 1.8.0_91 Scala - 2.11.8 Library - it.geosolutions.imageio-ext imageio-ext-tiff 1.1.15 We are reading lots of old TIF images and for some reason read is highly inconsistent - for some reasons on a different run reading the same image can succeed or fail with exception - javax.imageio.IIOException: Invalid component ID 3 in SOS at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method) at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java

Drawing certain parts of image offset from the corner?

纵饮孤独 提交于 2019-12-09 01:53:17
问题 I'm using a sprite sheet of sorts to load in spaceships. The documentation of Graphics.drawImage() states the arguments are boolean Graphics.drawImage(Image img, int dstx1, int dsty1, int dstx2, int dsty2, int srcx1, int srcy1, int srcx2, int srcy2, ImageObserver observer); However, the documentation says that dstx1 and dsty2 are the coordinates of the top left corner, and when you use dstx2 and dsty2 to specify the area drawn, the dimensions are (dstx2- dstx1) and (dsty2 - dsty1). Unless I'm

Is there an easy way to reduce the number of colors in an IndexedColorModel?

∥☆過路亽.° 提交于 2019-12-08 08:04:06
问题 I have a large 8-bit PNG image. I am using Java to slice the image into smaller 32x32 images. I use Java's ImageIO to load the PNG into a BufferedImage and then call it's getSubimage(x, y, 32, 32) . I then use ImageIO to write each tile out as a PNG. The problem is that the resulting image has the same IndexColorModel as the original image. For example, one 32x32 tile has only 8 total colors but it includes a color model with all 100-odd colors from the original image. I would like to remove

Java - Multithreading with ImageIO

≡放荡痞女 提交于 2019-12-08 04:16:33
问题 I have a program that loads slowly, which I guess is due to the amount of image resources I have to load at the beginning. I thought multi-threading would help, but now I'm not so sure. Here is my automatic multi-threading method. private static Thread[] t; private static int currentThreads; public static void loadWithThreads(Object[] array, IntegerRunnable r) { final int threads = Runtime.getRuntime().availableProcessors(); t = new Thread[threads]; for (int i = 0; i < threads; i ++) { t[i] =

Java ImageIO Grayscale PNG Issue

耗尽温柔 提交于 2019-12-07 15:27:49
问题 I have a grayscale image ("lena" actually) which I want to experiment with. I got it as a 512x512 PNG file with 216 shades of gray. What happens is, when I read it with Java ImageIO, like that: String name = args[0]; File fi = new File(name); BufferedImage img = ImageIO.read(fi); I get a BufferedImage with only 154 colours ! I only realized this, cause my processed images which looked sallow, lacking deep black. Even more irritating, when I use XnView convert the PNG to a GIF, which is a