|
@@ -626,5 +626,26 @@ CV_API bool HBitmap2Mat(HBITMAP& bitmap, cv::Mat& img)
|
|
|
|
|
|
CV_API bool GdiplusBitmap2Mat(Gdiplus::Bitmap& bitmap, cv::Mat& img)
|
|
CV_API bool GdiplusBitmap2Mat(Gdiplus::Bitmap& bitmap, cv::Mat& img)
|
|
{
|
|
{
|
|
- return CV_API bool();
|
|
|
|
|
|
+ Gdiplus::PixelFormat format = bitmap.GetPixelFormat();
|
|
|
|
+ if (format != PixelFormat24bppRGB)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ int width = bitmap.GetWidth();
|
|
|
|
+ int height = bitmap.GetHeight();
|
|
|
|
+
|
|
|
|
+ Gdiplus::Rect rcLock(0,0,width,height);
|
|
|
|
+ Gdiplus::BitmapData bmpData;
|
|
|
|
+
|
|
|
|
+ if ( !bitmap.LockBits(&rcLock, Gdiplus::ImageLockModeRead, format, &bmpData) == Gdiplus::Ok )
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ img = cv::Mat(height, width, CV_8UC3, static_cast<unsigned char*>(bmpData.Scan0), bmpData.Stride).clone();
|
|
|
|
+ bitmap.UnlockBits(&bmpData);
|
|
|
|
+
|
|
|
|
+ if (img.empty())
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ return true;
|
|
}
|
|
}
|