SurfaceView 到位图
我正在尝试将我的 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));
}
};
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 - 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));
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在尝试从 VideoView 获取视频帧时遇到类似的问题。我已经尝试过这些标志的各种组合:
...(稍后在另一个视图的draw()循环中)
但是“curFrame”位图图像,即使不为空,在调试器中的宽度和高度也为-1。这可能是某种 DRM 实现或其他什么,或者只是解码器的限制,但我认为不可能获取视频像素。您的相机可能会比较好运 - 您尝试过使用 setWillNotCacheDrawing() 吗?让我知道它是否有效,因为那是我的后备计划!
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:
... (later in another View's draw() loop)
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!
我让它与 PreviewCallback 一起使用:
public void onPreviewFrame(byte[] _data, Camera _camera) {
}
I got it to work with using the PreviewCallback:
public void onPreviewFrame(byte[] _data, Camera _camera) {
}