I work with files GeoTiff/PNGtoo large to handle in general in my code.
Is it possible to decode certain areas (for example, given by two x, y coordinates) of a file in bitmapfactory? We did not find anything similar to http://developer.android.com/reference/android/graphics/BitmapFactory.html(link for Android developers).
Thanks!
With the hint of kcoppock, I installed the following solution.
Although I wonder why rectyou need to initialize with Rect(left, bottom, right, top)instead Rect(left, top, right, bottom)...
Call example:
Bitmap myBitmap = loadBitmapRegion(context, R.drawable.heightmap,
0.08f, 0.32f, 0.13f, 0.27f);
Functions:
public static Bitmap loadBitmapRegion(
Context context, int resourceID,
float regionLeft, float regionTop,
float regionRight, float regionBottom) {
InputStream is = context.getResources().openRawResource(resourceID);
BitmapFactory.Options opt = new BitmapFactory.Options();
BitmapRegionDecoder decoder = null;
try {
decoder = BitmapRegionDecoder.newInstance(is, false);
} catch (IOException e) {
e.printStackTrace();
}
int h = decoder.getHeight();
int w = decoder.getWidth();
Rect region = new Rect(
Math.round(regionLeft*w), Math.round(regionBottom*h),
Math.round(regionRight*w), Math.round(regionTop*h));
return decoder.decodeRegion(region, opt);
}
source
share