将jpeg / png转换为java中的像素数组 [英] Convert jpeg/png to an array of pixels in java
本文介绍了将jpeg / png转换为java中的像素数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将包含jpeg或png的字符串转换为像素的数组(最好是一维)?理想情况下使用内置于java的类?
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?
推荐答案
事实证明你需要 commons-fileupload 。查看用户指南,了解如何获取图像 InputStream
。从那里你可以简单地调用:
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:
- 循环图像尺寸以及每次x和y调用
int rgb = image.getRGB(x,y);
- 与上述相同,但调用
getRed(x,y)
,getGreen(x,y)
,getBlue(x,y)
- 获取
ColorModel
和在那里调用上述方法 - 调用
getRGB(startX,startY,w,h,rgbArray,offset,scansize)
- 调用
getData()
,返回Raster
,然后调用getPixes(..)
那里
- 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 aRaster
, and callgetPixes(..)
there
这篇关于将jpeg / png转换为java中的像素数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文