保存位图图像

时间:2014-09-03 10:26:15

标签: c# winforms bitmap save

我正在尝试修改机器视觉库(Common Vision Blox)的示例。该示例从摄像机获取图像,将其转换为位图格式,并通过PictureBox显示给用户。

我想要的是将数据保存到文件中,但我得到一个全黑的BMP。我尝试了一些变种,但结果是一样的。

如果我从PictureBox保存图像,使用PictureBox.SaveImage,如果我

,结果是一样的

代码是这样的:

private Bitmap  _bm;
private bool    _bRequiresCopy;
private void cvImg_ImageUpdated(object sender, EventArgs e)
{
  // create a bitmap out of the image
  _bm = CvbImageToBitmap(cvImg.Image, out _bRequiresCopy);
  // and display it in the picture box

  //if (_bm != null) // Only this two lines in the original code 
  //    pictureBox.Image = _bm; 

  if (_bm != null)
  {          
      pictureBox.Image = _bm;

      // Tests to save

      _bm.Save("c:\\test.bmp"); // This don't work

      // The following don't work, but if add a button to the form and just place in the click 
      // event of the button it stores the image correctly
      pictureBox.Image.Save("c:\\test2.bmp"); 

      Bitmap TestBMP = new Bitmap(_bm);
      TestBMP.Save("c:\\test3.bmp"); // This don't work

  }
  // setup grab checkbox
  chkGrab.Enabled = cvImg.IsGrabber;
  chkGrab.Checked = false;
}

0 个答案:

没有答案