Create a bitmap from a specified area of ​​the screen

I am trying to create a bitmap from a specific area on the screen. For example, in the following figure, how can I capture the window area below and convert it to a bitmap?

Image

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

+8
android bitmap
source share
1 answer

In fact, you can use Android BitmapRegionDecoder.decodeRegion() after creating an InputStream from Bitmap .

You can pass a Rect object to the decodeRegion method, for example:

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

Greetings q :)

+12
source share

All Articles