joemoe
joemoe

Reputation: 5904

Java type that represents a PNG image?

What is a Java type which can hold a PNG implement and provide access to it's pixel buffer?

Upvotes: 1

Views: 4553

Answers (4)

Stew
Stew

Reputation: 1921

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.

Upvotes: 1

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45324

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

Upvotes: 14

mP.
mP.

Reputation: 18266

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

Upvotes: 1

MarkPowell
MarkPowell

Reputation: 16540

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

Upvotes: 3

Related Questions