Question

I am using BitmapRegionDecoder.decodeRegion(...) to crop image. But it does not work for android 2.3.1 (api level 10 ) and below. Please let me know is there any alternative way to achieve this. Even android-support-v4.jar library does not contain this class.

Was it helpful?

Solution

You can use Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height) to crop an image. It's been around since always, so provides an alternative for older APIs.

The documentation is pretty self-explanatory:

Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap.

Parameters

source    The bitmap we are subsetting
x         The x coordinate of the first pixel in source
y         The y coordinate of the first pixel in source
width     The number of pixels in each row
height    The number of rows

Returns A copy of a subset of the source bitmap or the source bitmap itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top