【发布时间】:2018-03-20 03:00:32
【问题描述】:
我正忙于一个 C# winform 软件。我使用网络摄像头拍摄显示在图片框中的图片。
当我使用网络摄像头拍摄图像时,它会拍摄一张放大的图像,而在打印时,它是一张拉伸的图像。我尝试了各种SizeMode 设置。所有的结果都一样
因为我不确定问题出在哪里,所以我会尽可能详细地说明:
使用
using AForge.Video;
using AForge.Video.DirectShow;
选择相机:
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
cmbVideoList.Items.Add(VideoCaptureDevice.Name);
}
使用相机(btn 点击):
cam = new VideoCaptureDevice(webcam[cmbVideoList.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
if (cam.IsRunning)
{
btnStart.Hide();
}
btnStop.Show();
}
void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
pboxPhoto.Image = bit;
}
图片框大小:
宽度:226
身高:328
打印代码:
PictureBox pict = (PictureBox)pboxPhoto;
pict.SizeMode = PictureBoxSizeMode.Zoom;
e.Graphics.DrawImage(pict.Image, 20, 416, 305, 328);
这是软件上的图像示例: enter image description here
打印图像的样本。 enter image description here
【问题讨论】:
-
PBox 图像始终是原始图像。您可以使用 DrawToBitmap 创建缩放版本或使用两个 Rectangle 进行绘制以自己进行任何拉伸..
-
会尝试的。谢谢。我是 C# 新手,是否在“打印代码”中使用 DrawToBitMap?
-
是或者只要图像准备好了..
-
@TaW 我正在与 DrawToBitMap 作斗争。你能帮我提供示例代码吗?
-
using (Bitmap bmp = new Bitmap(pboxPhoto.Width, pboxPhoto.Height)) { pboxPhoto.DrawToBitmap(bmp, new Rectangle( Point.Empty, bmp.Size)); //bmp.Save("D:\\patternDraw_.png", ImageFormat.Png); // or print it! }- 请注意,如果 PBox 有边框,您应该将大小调整为pboxPhoto.ClientSze.Width等。
标签: c# webcam picturebox webcam-capture