读书人

调用摄像头录像后 返回用pictureBox展

发布时间: 2012-01-19 20:57:58 作者: rapoo

调用摄像头录像后 返回用pictureBox展示一张图片 怎么做??
如题 微软官方 给了一个例子
private void videoMenuItem_Click(object sender, EventArgs e)
{
CameraCaptureDialog cameraCaptureDialog = new CameraCaptureDialog();
cameraCaptureDialog.Owner = this;
cameraCaptureDialog.Title = "Take Exhibit Video";
cameraCaptureDialog.Mode = CameraCaptureMode.VideoWithAudio;
if(cameraCaptureDialog.ShowDialog() == DialogResult.OK &&

cameraCaptureDialog.FileName.Length > 0)
{
fileExtension = Path.GetExtension(cameraCaptureDialog.FileName);
File.Copy(cameraCaptureDialog.FileName, fileName());
ComponentResourceManager resources =
new ComponentResourceManager(typeof(ExhibitForm));
pictureBox.Image = ((System.Drawing.Image)
(resources.GetObject("pictureBox.Image"))); ;
}
}


但是没成功 不知道为什么
ExhibitForm 应该是窗口的ID吧??

[解决办法]

C# code
using (CameraCaptureDialog cameracp = new CameraCaptureDialog())            {                cameracp.Title = "Camera";                cameracp.Mode = CameraCaptureMode.Still;                try                {                    if (cameracp.ShowDialog() == DialogResult.OK &&                    cameracp.FileName.Length > 0)                    {                        Image bitmap = new Bitmap(cameracp.FileName);                        MemoryStream imageStream = new MemoryStream();                        bitmap.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);                        bitmap.Clone();                        bitmap.Dispose();                        Byte[] imby = imageStream.GetBuffer();                        imageStream.Close();                        System.IO.File.Delete(cameracp.FileName);                        cameracp.Dispose();                        MemoryStream me = new MemoryStream(imby);                        Bitmap bitmaps = new Bitmap(me);                        newdisposal.Image = bitmaps;                                          }                }                catch (Exception cpex)                {                    cameracp.Dispose();                    MessageBox.Show(                         "照像机打开失败.建议重新启动程序.\r\n" + cpex.Message,                         "系统提示",                         MessageBoxButtons.OK,                         MessageBoxIcon.Hand,                         MessageBoxDefaultButton.Button1);                    return;                }            } 

读书人网 >Windows Mobile

热点推荐