Mat2Bitmap
作者:
小小蒟蒻
,
2021-02-28 21:59:25
,
所有人可见
,
阅读 556
using namespace cv;
int width, height;
Mat image = imread("D:\\123.jpg");
width = image.cols;
height = image.rows;
if (width % 4) width = (width + 3) / 4 * 4;
Size winSize(width, height);
Mat cvImgTmp(winSize, CV_8UC3);
if (image.size() != winSize)
resize(image, cvImgTmp, winSize);
else
cvImgTmp = image.clone();
CRect rect;
GetDlgItem(IDC_STATIC_IMAGE)->GetClientRect(&rect);
BITMAPINFO bitmapInfo;
BITMAPINFOHEADER* bmiHeader;
bmiHeader = &bitmapInfo.bmiHeader;
memset(bmiHeader,0, sizeof(BITMAPINFOHEADER));
bmiHeader->biSize = sizeof(BITMAPINFOHEADER);
bmiHeader->biWidth = width;
bmiHeader->biHeight = -height;
bmiHeader->biPlanes = 1;
bmiHeader->biBitCount = 24;
bmiHeader->biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = width * height;
bmiHeader->biXPelsPerMeter = 0;
bmiHeader->biYPelsPerMeter = 0;
bmiHeader->biClrUsed = 0;
bmiHeader->biClrImportant = 0;
auto pDC = GetDlgItem(IDC_STATIC_ORG)->GetDC();
pDC->SetStretchBltMode(HALFTONE);
StretchDIBits(pDC->GetSafeHdc()
, 0, 0, std::min(rect.Width(), rect.Height()), std::min(rect.Width(), rect.Height())
, 0, 0, cvImgTmp.cols, cvImgTmp.rows, cvImgTmp.data, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);