Saving canvas to bitmap on Android

前端 未结 5 1520
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 13:24

I\'m having some difficulty with regards to placing the contents of a Canvas into a Bitmap. When I attempt to do this, the file gets written with a file size of around 5.80K

5条回答
  •  Happy的楠姐
    2021-01-05 14:03

    You'll have to draw after setting the bitmap to the canvas. Also use a new Canvas object like this:

    Canvas canvas = new Canvas(toDisk);
    canvas.drawPath(currentPath, pen);
    toDisk.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(new File("arun.png")));
    

    I recommend using PNG for saving images of paths.

提交回复
热议问题