我想将画布从SurfaceView保存到位图以将其存储在智能手机上。我已经搜索了一些教程,并尝试了这样:
public void saveImage(){
Canvas canv = this.holder.lockCanvas();
Bitmap bitmap = Bitmap.createBitmap(canv.getWidth(), canv.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
this.holder.unlockCanvasAndPost(canv);
this.view.draw(canvas);
try{
bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(new File("/SD-Karte/Pictures/test.png")));
} catch(Exception e){
Log.e("Error --->", e.toString());
}
}
当我点击按钮保存图片时,我的应用程序停止工作,我没有收到任何错误。你们有什么提示我在这里做错了什么?