I am trying to load an Gdiplus bitmap of 8 bit depth to an opencv mat. the image is in greyscale.Greysacle Image of 8bit.
this is the VC++ code snippet i am using to convert it into cv::mat. But using this when i convert i am getting a faded image of the original image in the cv::mat. What could be the reason?
// Creating the m_Bitmap
Gdiplus::Bitmap bit(152, 152, PixelFormat8bppIndexed);
m_Bitmap = bit.Clone(0, 0, bit.GetWidth(), bit.GetHeight(), PixelFormat8bppIndexed);
// Later Different paths are added to this bitmap
// Converting this bitmap to cv::mat
Gdiplus::PixelFormat format = m_Bitmap->GetPixelFormat();
if (format == PixelFormat8bppIndexed)
{
Gdiplus::BitmapData bitmapData;
Gdiplus::Rect rect(0, 0, width, height);
m_Bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead, format, &bitmapData);
cv::Mat nmat = cv::Mat(height, width, CV_8UC1, static_cast<unsigned char*>(bitmapData.Scan0), bitmapData.Stride).clone();
}
Original bitmap Image (m_Bitmap)
enter image description here
This is the image preview of cv::mat nmat
enter image description here
I need to have the same image as the source to be loaded into the cv::mat but that is not happening here.
Jishnu JK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.