从指定的屏幕区域创建位图 [英] Create bitmap from specified screen area

查看:140
本文介绍了从指定的屏幕区域创建位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

干杯问:)

这篇关于从指定的屏幕区域创建位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆