开发者

Java type that represents a PNG image?

开发者 https://www.devze.com 2022-12-14 12:35 出处:网络
What is a Java type which can hold a PNG implement and prov开发者_如何学Pythonide access to it\'s pixel buffer?BufferedImage img = ImageIO.read(new File(\"my.png\"));

What is a Java type which can hold a PNG implement and prov开发者_如何学Pythonide access to it's pixel buffer?


BufferedImage img = ImageIO.read(new File("my.png"));
int color = img.getRGB(23,12);


I would take a look at Java Advanced Imaging, it handle multiple types of image files.


Take a look ImageIO and its numerous static helpers for reading and writing bytes/streams containing an image.


If you want to do pixel based operations on the entire image, I've found calling the getRGB() method every time to be fairly slow. In that case, you might want to try and get access to the actual pixel array holding the image data using something like:

byte[] pixel_array = ((DataBufferByte)img.getRaster().getDataBuffer()).getData()

There may be a more flexible way that doesn't make any presumptions on the array data type.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号