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?
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:
int rgb = image.getRGB(x, y);
getRed(x, y)
, getGreen(x, y)
, getBlue(x, y)
ColorModel
and call the above methods there getRGB(startX, startY, w, h, rgbArray, offset, scansize)
getData()
, which returns a Raster
, and call getPixes(..)
there Use PixelGraber . It returns one-dimensional array of RGB data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.