本文介绍了以SurfaceView的截屏与摄像机preVIEW它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个功能,其中包括拍照,录制视频。这是我的结论使用SurfaceView的截图方法的原因。
然而,当我尝试采取SurfaceView的屏幕截图。我总是得到一个空白影像。

I am trying to Implement a Functionality that includes taking Pictures While Recording Video. That's the reason i have concluded to use the Screenshot approach of SurfaceView.
However, when i try to take the Screen Shot of SurfaceView. I am always getting a Blank Image.

下面是我使用的拍摄快照的code:

Here is the code that i am using for taking a Snapshot:

View tempView = (View)MY_SURFACE_VIEW;
tempView.setDrawingCacheEnabled(true);
Bitmap tempBmp = Bitmap.createBitmap(tempView.getDrawingCache());
tempView.setDrawingCacheEnabled(false);
//Saving this Bitmap to a File....

在的情况下,你们可能会认为这是一个重复的问题,让我向你们保证,我曾试图询问此人之前提供的,因此对于同一问题通过以下方法解决。

In case you guys may think this is a duplicate Question, let me assure you that i have tried the following Solutions provided on SO for the same Problem before asking this one.

  1. Issue用相机拍照的机器人使用surfaceview快照
  2. Facing问题采取截图,同时记录视频
  3. Take相机的屏幕截图,同时记录 - 就像银河S3
  4. Taking截屏SurfaceView的机器人
  5. 获取surfaceView在Android的截图(这是正确的答案,但部分回答。我已经问@sajar解释应答)
  1. Issue with camera picture taken snapshot using surfaceview in android
  2. Facing issue to take a screenshot while recording a video
  3. Take camera screenshot while recording - Like in Galaxy S3?
  4. Taking screen shot of a SurfaceView in android
  5. Get screenshot of surfaceView in Android (This is the correct answer, but Partially Answered. I have already asked @sajar to Explain the Answer)

在互联网其他资源:
1的2. http://www.phonesdevelopers.com/1795894/

Other Resources on Internet:
1. http://www.coderanch.com/t/622613/Android/Mobile/capture-screenshot-simple-animation-project2. http://www.phonesdevelopers.com/1795894/

这一切都不迄今已为我工作。我也知道,我们需要创建一些线程与表面相互作用持有人,并获取位图,从它。但我不知道如何实现。

None of this has worked so far for me. I also know that we need to create some Thread that interacts with the Surface Holder and Gets the Bitmap from It. But i am not sure how to implement that.

任何帮助是高度鸭preciated。

Any Help is Highly Appreciated.

推荐答案

下面是另一个问题:采取截图的SurfaceView

SurfaceViews有一个面部分和视图的一部分;您的code试图捕捉到视图的一部分。 表面部分是一个单独的层,而且也没有琐碎的抓取所有像素的方法。基本的困难在于你的应用程序是在表面上的制片人的一面,而不是消费者的一面,所以读像素背出是有问题的。需要注意的是底层的缓冲区的任何格式是最方便的数据生产者,所以摄像头preVIEW这将是一个YUV缓冲。

SurfaceViews have a "surface" part and a "view" part; your code tries to capture the "view" part. The "surface" part is a separate layer, and there's no trivial "grab all pixels" method. The basic difficulty is that your app is on the "producer" side of the surface, rather than the "consumer" side, so reading pixels back out is problematic. Note that the underlying buffers are in whatever format is most convenient for the data producer, so for camera preview it'll be a YUV buffer.

捕捉表面像素的最简单,最有效的方法是吸引他们两次,一次在屏幕上,一次捕获。如果你这样做与OpenGL ES的,在YUV到RGB转换很可能会由硬件模块,这将是比接受摄像头帧YUV缓冲和做自己的转换更快的完成。

The easiest and most efficient way to "capture" the surface pixels is to draw them twice, once for the screen and once for capture. If you do this with OpenGL ES, the YUV to RGB conversion will likely be done by a hardware module, which will be much faster than receiving camera frames in YUV buffers and doing your own conversion.

Grafika的纹理的相机活动演示操作与GLES输入的视频数据。使你可以用 glReadPixels像素后() glReadPixels的性能()可以显著的设备和不同的用例之间变化。 EglSurfaceBase#saveFrame()显示了如何捕捉到位图并保存为PNG。

Grafika's "texture from camera" activity demonstrates manipulation of incoming video data with GLES. After rendering you can get the pixels with glReadPixels(). The performance of glReadPixels() can vary significantly between devices and different use cases. EglSurfaceBase#saveFrame() shows how to capture to a Bitmap and save as PNG.

有关Android的图形架构中,SurfaceView表面特别是生产者 - 消费者的性质,更多信息可以在。

More information about the Android graphics architecture, notably the producer-consumer nature of SurfaceView surfaces, can be found in this document.

这篇关于以SurfaceView的截屏与摄像机preVIEW它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 03:53