Reputation: 1680
I have a transparent png image. I read that file using opencv. Then I am converting it to bitmap as follows.
Mat image = imread("fruit.png", -1);
BYTE * rawdata = reinterpret_cast<BYTE*>(image.data);
m_pBitmap->CopyFromMemory(NULL, rawdata, image.cols * 4);
m_pRenderTarget->DrawBitmap(m_pBitmap);
But after converting some images show some transparency problems... Same as in this link and the image is not showing full. But when we save that Mat image using imwrite there is no problem. So the problems I am facing are
Upvotes: 3
Views: 11583
Reputation: 630
You should convert the image format within OpenCV, since different libraries have their own decoding and representing methods.
Try the following codes:
Mat image = imread("fruit.png", -1);
Mat image_bmp;
image.convertTo(image_bmp, CV_8UC3);
imwrite("fruit.bmp", image_bmp);
You can specify in which format you want to save your image by .bmp
or .jpg
in the filename.
The result looks like this (after resize of course):
Upvotes: 3