我有一个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