如何使用SurfaceView作为图像保存画布绘图?

时间:2012-04-10 12:19:09

标签: android

如何使用SurfaceView将画布绘图保存为图像而不是视图。

1 个答案:

答案 0 :(得分:2)

尝试下面的代码可能有帮助

    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);
}