javax.imageio

How to read pixel color in a java BufferedImage with transparency

痴心易碎 提交于 2019-11-28 23:38:13
I am reading pixel color in a BufferedImage as follows: ..... InputStream is = new BufferedInputStream(conn.getInputStream()); BufferedImage image = ImageIO.read(is); int color = image.getRGB(x, y); int red = (colour & 0x00ff0000) >> 16; int green = (colour & 0x0000ff00) >> 8; int blue = colour & 0x000000ff; Now this works fine except for png's with transparency. I find that if x,y refer to a transparent pixel with no color, i still read a color, generally the same color as used elsewhere in the image. How do I detect that the pixel is actually transparent and not colored? Thanks int alpha =

ImageIO.read illegal argument exception - raster bands/colour space components?

主宰稳场 提交于 2019-11-28 21:24:10
Apologies for the somewhat vague title, I can't work out what the keywords are here. The setup's quite simple, I'm opening an image with ImageIO.read(new File(filename)); This works for most files, however for one I get an IllegalArgumentException with the detail: "numbers of source Raster bands and source color space components do not match" . This image was obtained via wget on a valid Flickr URL, and I've used other images obtained this way, so the method for obtaining images seems sound in principle. I'm not sure what's causing the exception. A workaround would be more than acceptable - I

Download an image from a URL?

拈花ヽ惹草 提交于 2019-11-28 21:17:15
I am trying to use HTTP::get to download an image of a Google chart from a URL I created. This was my first attempt: failures_url = [title, type, data, size, colors, labels].join("&") require 'net/http' Net::HTTP.start("http://chart.googleapis.com") { |http| resp = http.get("/chart?#{failures_url") open("pie.png" ,"wb") { |file| file.write(resp.body) } } Which produced only an empty PNG file. For my second attempt I used the value stored inside failure_url inside the http.get() call. require 'net/http' Net::HTTP.start("http://chart.googleapis.com") { |http| resp = http.get("/chart?chtt=Builds

Java ImageIO IIOException: Unsupported image type?

萝らか妹 提交于 2019-11-28 19:13:09
Working with images in Java for the first time and am getting some bizarro exceptions that aren't documented very well. Here's the line of code that is failing: BufferedImage imgSelected = ImageIO.read(new File("/abs/url/to/file/image.jpg")); This line is throwing an IIOException with Unsupported image type as the exception message. I have checked and re-checked that it is in fact this line throwing the exception, that the File object is valid, that the URL is valid, and that the image.jpg is in fact a valid JPG that loads perfectly fine in other image viewers. What could I do to get more

Manipulate an image without deleting its EXIF data

情到浓时终转凉″ 提交于 2019-11-28 18:53:48
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? 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.setInput(ImageIO.createImageInputStream(your_imput_stream)); Now you may save your metadata: IIOMetadata

Trying to load image using ImageIO.read(class.getResource(URL)) but getResource is returning null

寵の児 提交于 2019-11-28 13:55:24
I've been making a 2D game with my buddy and I've been learning a lot about some basic game dev concepts through some Youtube tutorials. One of the things I was learning about is sprites (for those that don't know, 2D images to render to the screen) and how to use them in my game. I've been using ImageIO.read(this.class.getResource(pathToMySprite)) but it seems that getResource() is returning null for some reason. I've been screwing around with the path a little, adding "/" in front of it, removing "/", putting the user.dir property to see if it needed the whole path, and I'm still getting the

Why does ImageReader return incorrect BufferedImage?

亡梦爱人 提交于 2019-11-28 13:43:06
I'm trying to access a animated GIF image with 21 frames and then read the 12th (cause it starts at 0?) frame. import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.IOFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter; public class PictureSearch { public static void

How to get favicon.ico from a website using Java?

半腔热情 提交于 2019-11-28 13:18:14
So I'm making an application to store shortcuts to all the user's favorite applications, acting kind of like a hub. I can have support for actual files and I have a .lnk parser for shortcuts. I thought it would be pretty good for the application to support Internet shortcuts, too. This is what I'm doing: Suppose I'm trying to get Google's icon ( http://www.google.com/favicon.ico ). I start out by getting rid of the extra pages (e.g. www.google.com/anotherpage would become www.google.com . Then, I use ImageIO.read(java.net.URL) to get the Image. The problem is that ImageIO never returns an

Strange PNG errors: Bad length for IHDR chunk

浪子不回头ぞ 提交于 2019-11-28 11:46:41
Heres the error: Exception in thread "main" javax.imageio.IIOException: I/O error reading PNG header! at com.sun.imageio.plugins.png.PNGImageReader.readHeader(PNGImageReader.java:307) at com.sun.imageio.plugins.png.PNGImageReader.readMetadata(PNGImageReader.java:637) at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1212) at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1560) at javax.imageio.ImageIO.read(ImageIO.java:1422) at javax.imageio.ImageIO.read(ImageIO.java:1282) at Bundle.iconExists(Bundle.java:139) at Bundle.dPhIconExists(Bundle.java

Eclipse missing imports (javax.media.* and com.sun.media.*)

孤者浪人 提交于 2019-11-28 11:30:21
I have this old java applet that i need to debug, yet i have some problems with import. The import javax.media.* cannot be resolved. The import com.sun.media.* cannot be resolved After some research i tried adding this external libs to the project - with no success. sun-jai_codec.jar from http://www.java2s.com/Code/Jar/s/Downloadsunjaicodecjar.htm installed JMF2.1.1e and added the jmf.jar. I had no luck with this... so im asking some one for a little help! Just build the path of your project again. Right click on the project and then select build path--->configure build path--->java build path