我有一個C++的DLL構建,並將返回Mat對象。 該圖片信息是384 * 384 * 24色。C + + DLL返回到C##
C#代碼
Bitmap a = new Bitmap(384, 384, 3 * 384, PixelFormat.Format24bppRgb, test1());
pictureBox0.Image = a;
C++代碼
uchar* DLL_EXPORT test1(void)
{
Mat OriginalImg = imread("c:\\20100812133.jpg", 1);
return OriginalImg.data;
}
在代碼都OK,但我想讀在灰色圖片。 我會做一些圖像處理(例如:Threshod),並轉換爲顏色, 並返回到C#並顯示它!
C++代碼
uchar* DLL_EXPORT test0(void)
{
Mat OriginalImg = imread("c:\\20100812133.jpg", 0);
threshold(OriginalImg,OriginalImg,0,255,THRESH_OTSU);
cvtColor(OriginalImg,OriginalImg,CV_GRAY2BGR);
return OriginalImg.data;
}
C++代碼失敗了,你能幫忙嗎?
UPDATA http://ppt.cc/h2SI圖片是失敗,我認爲原因是內存。 我修復了c#代碼第3個參數3 * 384到2 * 384。 C#運行正常,但畫面打破這樣http://ppt.cc/IRfd
- UPDATA
Bitmap a = new Bitmap(384, 384, 1 * 384, PixelFormat.Format24bppRgb, test0());
Bitmap a = new Bitmap(384, 384, 2 * 384, PixelFormat.Format24bppRgb, test0());
Bitmap a = new Bitmap(384, 384, 3 * 384, PixelFormat.Format24bppRgb, test0());
Bitmap a = new Bitmap(384, 384, 2 * 384, PixelFormat.Format32bppRgb, test0());
Bitmap a = new Bitmap(384, 384, 3 * 384, PixelFormat.Format32bppRgb, test0());
Bitmap a = new Bitmap(384, 384, 4 * 384, PixelFormat.Format32bppRgb, test0());
我嘗試六,運行是好的,但圖片是休息。
什麼樣的故障?詳細信息,請。 – egrunin 2012-07-23 14:38:32
您需要在此設置不同的圖片格式PixelFormat.Format24bppRgb或將圖片數據轉換爲此數據類型描述的格式 – Sam 2012-07-23 14:55:03