Android: Cropping an image to specific size

后端 未结 2 471
鱼传尺愫
鱼传尺愫 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.

    0 讨论(0)
  • 2021-02-02 05:03
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null)
                .setType("image/*")
                .putExtra("crop", "true")
                .putExtra("aspectX", width)
                .putExtra("aspectY", height)
                .putExtra("outputX", width)
                .putExtra("outputY", height)
                .putExtra("scale", true)
                .putExtra("scaleUpIfNeeded", true)
                .putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f))
                .putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    
    0 讨论(0)
提交回复
热议问题