从指定的屏幕区域创建位图位图、屏幕、区域

2023-09-08 09:36:06 作者:毁灭性喜欢

我想在屏幕上的特定区域创建位图。例如下图中我怎么能捕捉到下面的窗面积,并将其转换成位图?

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?

我知道你可以使用setDrawingCacheEnabled(真),但捕捉全景,当所有我想要的是在视图中的区域。

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

推荐答案

您可以实际使用Android的 Bitma pregionDe coder.de codeRegion()创建后的InputStream 位图

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

您可以通过一个矩形对象的德codeRegion像这样方法:

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);

干杯问:)

 
精彩推荐
图片推荐