Saving canvas to bitmap on Android

前端 未结 5 1533
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  清歌不尽
    2021-01-05 13:52

    first create a blank bitmap , then create a canvas with that blank bitmap

     Bitmap.Config conf = Bitmap.Config.ARGB_8888; 
     Bitmap bitmap_object = Bitmap.createBitmap(width, height, conf); 
     Canvas canvas = new Canvas(bitmap_object);
    

    now draw your lines on canvas

           Path currentPath = new Path();
            boolean IsFirst = true;
            for(Point point : currentPoints){
                if(IsFirst){
                    IsFirst = false;
                        currentPath.moveTo(point.x, point.y);
                    } else {
                        currentPath.lineTo(point.x, point.y);
                    }
                }
    
            // Draw the path of points
            canvas.drawPath(currentPath, pen);
    

    Now access your bitmap via bitmap_object

提交回复
热议问题