Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create bitmap from specified screen area

Tags:

android

bitmap

I'm trying to create a bitmap from a specific area on the screen. For example in the following image how could I capture the windowed area below and convert it into a bitmap?

Image

I know you can use setDrawingCacheEnabled(true), but that captures the whole view, when all I want is an area within the view.

like image 262
John Smith Avatar asked Jul 08 '13 13:07

John Smith


1 Answers

You can actually use Android's BitmapRegionDecoder.decodeRegion() after you create an InputStream from your Bitmap.

You can pass a Rect object to the decodeRegion method like so:

BitmapRegionDecoder brd = BitmapRegionDecoder.newInstance(inputStream, true);
Bitmap croppedBitmap = brd.decodeRegion(new Rect(left, top, right, bottom), null);

Cheers q:)

like image 125
woot Avatar answered Oct 22 '22 02:10

woot