【发布时间】:2013-11-10 23:04:50
【问题描述】:
我目前有一个工作程序,它显示来自我的网络摄像头的预览并使用 ISampleGrabberCB 界面。
使用SampleCB 我的程序将图像转换为位图,然后将图像处理为条形码,然后解码。当我使用MessageBox 显示结果时,这非常有效,但是当我希望使用此结果编辑主窗体上的文本框时,我在启动程序时会遇到一些错误。
我正在尝试使用ISampleGrabberCB 界面中的以下代码更新我的文本框:
public int SampleCB(double sampletime, IMediaSample sample)
{
if (sample == null)
{
return -1;
}
try
{
int length = sample.GetActualDataLength();
IntPtr buffer;
BitmapData bitmapData = new BitmapData();
Form1 f1 = new Form1("", "", "");
if (sample.GetPointer(out buffer) == 0 && length > 0)
{
Bitmap bitmapOfFrame = new Bitmap(width, height, pitch, PixelFormat.Format24bppRgb, buffer);
}
方法changeTextBox1在我的主窗体中,如下:
public void changeTextBox1(string text)
{
textBox1.Text = text;
}
我得到的错误首先是A device attached to the system in not functioning properly,然后是no such supported interface。这似乎只在我使用 Form1 f1 = new Form1("","",""); 行时才会发生。
所以正如我所说,如果我删除行 Form1 f1 = new Form1("","",""); 并将 changeTextBox1(result.Text); 替换为 MessageBox.Show(result.Text.ToString()); 这有效。
我将如何更新文本框而不是使用 MessageBox?
【问题讨论】:
标签: c# winforms bitmap directshow directshow.net