相关疑难解决方法(0)

使用MediaProjection截取屏幕截图

借助MediaProjectionAndroid L中提供的API,可以实现

将主屏幕的内容(默认显示)捕获到Surface对象中,然后您的应用可以通过网络发送该对象

我已经设法让VirtualDisplay工作,我SurfaceView正确显示屏幕的内容.

我想要做的是捕获显示在其中的框架Surface,并将其打印到文件.我尝试过以下内容,但我得到的只是一个黑色文件:

Bitmap bitmap = Bitmap.createBitmap
    (surfaceView.getWidth(), surfaceView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
surfaceView.draw(canvas);
printBitmapToFile(bitmap);
Run Code Online (Sandbox Code Playgroud)

有关如何从中检索显示数据的任何想法Surface

编辑

因此,作为@j__m建议,现在我的设置VirtualDisplay使用SurfaceImageReader:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
displayWidth = size.x;
displayHeight = size.y;

imageReader = ImageReader.newInstance(displayWidth, displayHeight, ImageFormat.JPEG, 5);
Run Code Online (Sandbox Code Playgroud)

然后我创建虚拟显示传递SurfaceMediaProjection:

int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;

DisplayMetrics metrics = getResources().getDisplayMetrics();
int density = metrics.densityDpi;

mediaProjection.createVirtualDisplay("test", …
Run Code Online (Sandbox Code Playgroud)

android bitmap surfaceview

18
推荐指数
4
解决办法
2万
查看次数

如何从ImageReader android获取InputStream

我正在看这个课程:https://developer.android.com/reference/android/media/ImageReader.html

我想要的是从ImageReader类中获取一个InputStream,并获取正在渲染到当前表面的图像数据.Current Surface表示当前显示的android屏幕.我在AOSP代码中查看了一个示例,但实际上很难理解.如果有人为我提供了一个很好的ImageReader类示例,那将非常有用.

java android file-descriptor fileinputstream surfaceview

0
推荐指数
1
解决办法
1766
查看次数