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?
-
string? in what format? base64? hex?Bozho– Bozho2010-02-03 21:53:32 +00:00Commented Feb 3, 2010 at 21:53
-
Does this string contain the file name of a file, or the raw image data?Anon.– Anon.2010-02-03 21:53:43 +00:00Commented Feb 3, 2010 at 21:53
-
again - in what format ?Bozho– Bozho2010-02-03 21:55:35 +00:00Commented Feb 3, 2010 at 21:55
-
whatever a POST HTTP file submission would be, I'm guessing base 64 encoded?Matt– Matt2010-02-03 21:57:42 +00:00Commented Feb 3, 2010 at 21:57
Add a comment
|
2 Answers
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
ColorModeland call the above methods there - call
getRGB(startX, startY, w, h, rgbArray, offset, scansize) - call
getData(), which returns aRaster, and callgetPixes(..)there