首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

调用摄像头录像后 返回用pictureBox展示一张图片 如何做?

2012-01-19 
调用摄像头录像后 返回用pictureBox展示一张图片 怎么做??如题 微软官方 给了一个例子private void videoM

调用摄像头录像后 返回用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;                }            } 

热点排行