【问题标题】:SurfaceView to BitmapSurfaceView 到位图
【发布时间】:2010-09-26 19:50:58
【问题描述】:

我正在尝试将我的 SurfaceView(相机预览)转换为位图以进行动态人脸检测。我收到一个非空图像,但是当我将它显示到视图上时,它看起来是纯黑色的。任何想法可能是什么原因以及如何进行?

(我认为从 SurfaceView 中提取位图很困难但并非不可能 - 但没有人发布任何解决方案)

class BackgroundView extends SurfaceView implements SurfaceHolder.Callback {


        public BackgroundView(Context context) {
            super(context);

                    // ...

            setDrawingCacheEnabled(true);
        }


        // ...
    }

    private Runnable update = new Runnable() {
        public void run() {

                    // Following statement is sending a black/blank image
            faceView.updateFaces(backgroundView.getDrawingCache());
            mHandler.postDelayed(update, (long) (1000));
        }
    };

【问题讨论】:

  • 你有什么解决方案吗,我也得到了纯空白图像。

标签: android bitmap surfaceview


【解决方案1】:

我使用 PreviewCallback 让它工作:

public void onPreviewFrame(byte[] _data, Camera _camera) {

    // data = byte array of the camera preview

}

【讨论】:

  • 我也想看看这个,拜托。
【解决方案2】:

我在尝试从 VideoView 获取视频帧时遇到了类似的问题。我已经尝试了这些标志的各种组合:

   vids[i] = new VideoView(this);
   vids[i].setDrawingCacheEnabled(true);
   vids[i].setWillNotCacheDrawing(false);
   vids[i].setWillNotDraw(false);

...(稍后在另一个 View 的 draw() 循环中)

curFrame = vids[0].getDrawingCache();
if (curFrame != null) {
   canvas.drawBitmap(curFrame, null, new RectF(10,y,50,y+50), null);
}

但“curFrame”位图图像,即使不为空,在调试器中的宽度和高度为 -1。它可能是某种 DRM 实现或其他东西,或者只是解码器的限制,但我认为不可能获得视频像素。您的相机可能会有更好的运气 - 您是否尝试过使用 setWillNotCacheDrawing()?让我知道它是否有效,因为那是我的后备计划!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    相关资源
    最近更新 更多