2

How can I convert a string containing a jpeg or png to an array (preferably one dimensional) of pixels? Ideally using classes built into java?

4
  • string? in what format? base64? hex? Commented Feb 3, 2010 at 21:53
  • Does this string contain the file name of a file, or the raw image data? Commented Feb 3, 2010 at 21:53
  • again - in what format ? Commented Feb 3, 2010 at 21:55
  • whatever a POST HTTP file submission would be, I'm guessing base 64 encoded? Commented Feb 3, 2010 at 21:57

2 Answers 2

6

It turns out you need commons-fileupload. Look at the user guide for how to obtain the image InputStream. From there you can simply call:

BufferedImage image = ImageIO.read(item.getInputStream());

From here on there are many ways:

  • loop over the image dimensions and for each x and y call int rgb = image.getRGB(x, y);
  • same as above, but call getRed(x, y), getGreen(x, y), getBlue(x, y)
  • get the ColorModel and call the above methods there
  • call getRGB(startX, startY, w, h, rgbArray, offset, scansize)
  • call getData(), which returns a Raster, and call getPixes(..) there
Sign up to request clarification or add additional context in comments.

Comments

0

Use PixelGraber. It returns one-dimensional array of RGB data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.