How do I get a Raster from an Image in java?

房东的猫 提交于 2019-12-02 11:34:32

问题


I'm trying to load a gif image from a url into a java.util.image.Raster so I can manipulate it. The only method for loading and decompressing an image I could find was Toolkit.getImage, which returns a java.awt.Image. I need to turn that into a Raster so I can work with it. Suggestions?


回答1:


Load your Image into a Buffered Image and then get the data from it

BufferedImage img = null;
try {
   img = ImageIO.read(new File ("c:/imageFile.gif"));
} catch(Exception e) {}

Raster R=img.getData();



回答2:


if you just want to draw on this image, you can get a Graphics2D context, from your BufferedImage.

Graphics2D g=(Graphics2D) image.getGraphics();
//draw over your image
g.drawLine(1,1,100,100);
g.dispose();
//save your image, display it, etc...


来源:https://stackoverflow.com/questions/982713/how-do-i-get-a-raster-from-an-image-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!