Freehand Image Crop draw inside bitmap region

前端 未结 3 1967
面向向阳花
面向向阳花 2021-02-06 02:54

Trying to achieve freehand cropping of an image, so I\'m able to draw on the image. But it goes outside bitmap region. I just wanna restrict that user can only draw inside bitma

3条回答
  •  无人共我
    2021-02-06 03:32

    late answer but use full for other u can override onmeasure method and set your image bitmap width and height in that method and resize your canvas so now you can draw only in your canvas.so your image come center.it for drawpath only on your bitmap.

     @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    
        height = bitmap.getHeight();
        width = bitmap.getWidth();
    
        setMeasuredDimension(width,height);
    }
    

    and then change in your oncrop method so you can slove it esaly.

    Bitmap resultingImage = Bitmap.createBitmap(yourbitmap.getwidth(),yourbitmap.getheight(), yourbitmap.getConfig());
    

提交回复
热议问题