开发者

SurfaceView to Bitmap

I am trying to convert my SurfaceView (camera preview) into a Bitmap for face detection on the fly. I am receiving a not null image but when I display it onto a view it appears to be plain black. Any ideas what might be the reason and how to proceed?

(I believe it is difficult but not impossible to extract the bitmap from a SurfaceView -开发者_JAVA技巧 but nobody has posted any solution)

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


I got it to work with using the PreviewCallback:

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

    // data = byte array of the camera preview

}


I'm having a similar problem trying to get the video frames from a VideoView. I've tried all kinds of combinations of these flags:

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

... (later in another View's draw() loop)

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

But the "curFrame" bitmap image, even though not null, has a width and height of -1 in the debugger. It may be some kind of DRM implementation or something, or just a limitation of the decoder, but I don't think it's possible to get the video pixels. You may have better luck with your camera - have you tried playing around with setWillNotCacheDrawing()? Let me know if it works because that was my fallback plan!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜