android equivalent code for graphics2D

寵の児 提交于 2019-12-24 02:23:51

问题


I have been trying to get an android equivalent code for the following :-

private BufferedImage user_space(BufferedImage image)
{
    BufferedImage new_img  = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D    graphics   = new_img.createGraphics();
    graphics.drawRenderedImage(image, null);
    graphics.dispose(); 
    return new_img;
}

I want an android equivalent of Graphics2D. I have been searching for a while and found out that Canvas in android can do some similar tasks as performed by the Graphics2D class here but the main problem is that I'm not getting the android equivalent of the whole process that is being performed in the code. Please anyone help ASAP...


回答1:


android does not have BufferedImage or Graphics2D as you probably already found out.

I'm not a java developer (just android) so I'm not 100% sure on what you're trying to achieve, but it seems to me that you're simply creating a copy of the image.

here a few classes that you'll be using for those type of manipulation:

  • Bitmap: that's like the BufferedImage, it's the object that actually stores all the bytes from the image (possibly large object with potential for memory crash). There're some static methods here for copy bitmaps, create new mutable or immutable bitmaps, scale, or compress as PNG or JPG to a stream.

  • BitmapFactory: lots of static methods to create new bitmaps from resources, files, streams, etc.

  • Canvas: You'll actually only use this one if you want to draw on the image (overlay image, put some text, or a line, stuff like that)



来源:https://stackoverflow.com/questions/15836712/android-equivalent-code-for-graphics2d

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