C# WINFORM 获取摄像头的帧
如何获取,获取后我再把这些帧显示在界面中,用picturebox轮流显示
------解决方案-------------------- buttonStart.Enabled = false;
buttonStop.Enabled = true;
//btnPz.Enabled = true;
video = new cVideo(picCapture.Handle, picCapture.Width, picCapture.Height);
video.StartWebCam();
-------------------------
private void buttonPz_Click(object sender, EventArgs e)
{
video.GrabImage(picCapture.Handle, "d:\\my.bmp");
}
------解决方案--------------------参考
Camera mCamera = Camera.open();
Camera.Parameters p = mCamera.getParameters();
p.setPreviewFormat(ImageFormat.NV21);
/*这是唯一值,也可以不设置。有些同学可能设置成 PixelFormat 下面的一个值,其实是不对的,具体的可以看官方文档*/
mCamera.setParameters(p);
mCamera.startPreview();
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Size size = camera.getParameters().getPreviewSize();
try{
YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null);
if(image!=null){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0, size.width, size.height), 80, stream);
Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
stream.close();
}
}catch(Exception ex){
Log.e("Sys","Error:"+ex.getMessage());
}
}