开发者

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

开发者 https://www.devze.com 2023-01-24 23:02 出处:网络
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.

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

精彩评论

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