当前位置: 技术问答>java相关
用java读取位图
来源: 互联网 发布时间:2015-06-17
本文导语: 在java中如何读位图,并分析它的灰度值,并分析出概率 谢谢!!!! | BufferedImage _image; String name="......."; Image loadedImage = Toolkit.getDefaultToolkit().getImage(name); MediaTra...
在java中如何读位图,并分析它的灰度值,并分析出概率
谢谢!!!!
谢谢!!!!
|
BufferedImage _image;
String name=".......";
Image loadedImage = Toolkit.getDefaultToolkit().getImage(name);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(loadedImage, 0);
try { tracker.waitForID(0); }
catch (InterruptedException e) {}
_image = new BufferedImage(loadedImage.getWidth(null),
loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = _image.createGraphics();
然后在调用
WritableRaster raster = _image.getRaster();
int[] pixels = new int[3];
raster.getPixel(x,y,pixels);
其中xy为某点的相对坐标
然后pixels中就是这个点的rgb值
String name=".......";
Image loadedImage = Toolkit.getDefaultToolkit().getImage(name);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(loadedImage, 0);
try { tracker.waitForID(0); }
catch (InterruptedException e) {}
_image = new BufferedImage(loadedImage.getWidth(null),
loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = _image.createGraphics();
然后在调用
WritableRaster raster = _image.getRaster();
int[] pixels = new int[3];
raster.getPixel(x,y,pixels);
其中xy为某点的相对坐标
然后pixels中就是这个点的rgb值