ilpimage to bitmap

Iplimage To Bitmap (銀展提供)



if (ipl->depth == 8)

{

if (ipl->nChannels == 3)

{

return gcnew System::Drawing::Bitmap(ipl->width , ipl->height , ipl->widthStep , System::Drawing::Imaging::PixelFormat::Format24bppRgb ,

(System::IntPtr)ipl->imageData); 

}

else

{

return gcnew System::Drawing::Bitmap(ipl->width , ipl->height , ipl->widthStep , System::Drawing::Imaging::PixelFormat::Format8bppIndexed ,

(System::IntPtr)ipl->imageData);

}

}



Bitmap To Iplimage 



IplImage* tmp;

System::Drawing::Imaging::BitmapData^ bmData = bitmap->LockBits(System::Drawing::Rectangle(0, 0, bitmap->Width, bitmap->Height) ,

System::Drawing::Imaging::ImageLockMode::ReadWrite, bitmap->PixelFormat);

if(bitmap->PixelFormat == System::Drawing::Imaging::PixelFormat::Format8bppIndexed)

{

tmp = cvCreateImage(cvSize(bitmap->Width , bitmap->Height) , IPL_DEPTH_8U , 1);

tmp->imageData = (char*)bmData->Scan0.ToPointer();

}

else if (bitmap->PixelFormat == System::Drawing::Imaging::PixelFormat::Format24bppRgb)

{

tmp = cvCreateImage(cvSize(bitmap->Width , bitmap->Height) , IPL_DEPTH_8U , 3);

tmp->imageData = (char*)bmData->Scan0.ToPointer();

}

你可能感兴趣的:(bitmap)