Android: Cropping an image to specific size

后端 未结 2 473
鱼传尺愫
鱼传尺愫 2021-02-02 04:31

My intention is to have the user pick an image from the gallery, then have a cropping activity come up. However, I need the rectangle that defines the cropping mask to be locked

2条回答
  •  孤城傲影
    2021-02-02 04:56

    You need to create a custom ImageView class to achieve zooming and panning of an image and can have a fixed rectangle image(transparent) overlaying on this image. And can create sub-bitmap of that bitmap. and save it in a file.

    createBitmap(Bitmap source, int x, int y, int width, int height);
    

    This method is used to create a sub-bitmap.

    http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

    After achieving zooming and panning, I am not sure if createBitmap can create sub-bitmap from the visible portion of the image(i.e. part of image wont be visible on the screen when it is zoomed), So try getting the drawingCache() from imageView and create sub-bitmap for the same.

提交回复
热议问题