我經歷過I方法比II慢。我的應用程序進行實時圖像處理。我知道C#對於這個目的並不理想,但我可以將性能關鍵的東西分開,並以C++爲例。我想知道爲什麼在C#中慢一個簡單的位圖繪圖沒有任何計算。我的問題是:在C#中有更快的方法,然後我?C#繪圖箱繪圖速度
I. C#:
void DrawImg(Bitmap b)
{
pictureBox1.Image = b;
pictureBox1.Invalidate();
}
II. C# + C++ + OpenCV
C# side:
[DllImport("MyWrapper.dll")]
static extern void showimg(IntPtr p, int x, int y);
void DrawImg(Bitmap b)
{
BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
showimg(d.Scan0, d.Width, d.Height);
b.UnlockBits(d);
}
C++ side:
extern "C" void __stdcall showimg(uchar* p, int x, int y)
{
Mat img; // OpenCV's Mat class
img.create(y, x, CV_8UC3);
img.data = p;
imshow("Window1", img);
}
感謝您的回覆。我的代碼不會轉換圖片(調整大小或打掃等),只需將位圖複製到屏幕即可。位圖的格式是32bppArgb,因爲這是默認值。 – bsebi 2010-12-16 20:39:16
PictureBox確實如此,這就是你的代碼片斷說你使用。重點是*改變*位圖格式,不要使用默認值。 – 2010-12-16 20:41:51
pictureBox1.SizeMode ==正常,所以沒有調整大小。現在我嘗試了不同的像素格式,但沒有太大的區別。 – bsebi 2010-12-16 22:36:06