开发者

How to save current state of canvas as an image in android

I'm developing an application which allows user to edit an image and save that edited image as new image on 开发者_如何学Gosd card I want to get the current state of the canvas object. please help me with this.


It's hard to answer without knowing more about how your image editor works. I will guess that it is a SurfaceView, which is commonly subclassed to allow arbitrary drawing.

SurfaceView provides an easy way to render the output to canvas and thus a bitmap.

Bitmap bitmap = Bitmap.createBitmap(mSurfaceView.getWidth(), mSurfaceView.getHeight(), Bitmap.Config.ARGB_8888);
mSurfaceView.draw(new Canvas(bitmap));
try {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(saved.png));
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (IOException e) {
    Log.w(TAG, e);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜