Bitmap ---> getRGB565 face检测

49 篇文章 0 订阅
    Bitmap  getRGB565(Bitmap bitmap){
        int i = bitmap.getWidth();
        int j = bitmap.getHeight();   //从上步解出的JPEG数组中接出BMP,即RAW->JPEG->BMP


        Matrix localMatrix = new Matrix();
        localMatrix.postRotate(0.0F, i / 2, j / 2);

        Bitmap bitmap_res = Bitmap.createBitmap(i, j, Bitmap.Config.RGB_565);

        Paint localPaint = new Paint();
        localPaint.setDither(true);

        Canvas localCanvas = new Canvas();
        localCanvas.setBitmap(bitmap_res);
        localCanvas.setMatrix(localMatrix);
        localCanvas.drawBitmap(bitmap, 0.0F, 0.0F, localPaint);
        return  bitmap_res;
    }
非常抱歉,我之前提供的代码中确实存在错误。在调用 `bitmap->GetHBITMAP()` 函数时,需要传递一个 `ColorPalette` 对象作为参数。以下是修正后的代码: ```cpp // ... void OpenFile() { OPENFILENAME ofn; wchar_t szFile[MAX_PATH] = { 0 }; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = g_hWnd; ofn.lpstrFile = szFile; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = L"PNG文件\0*.png\0"; ofn.nFilterIndex = 1; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileName(&ofn)) { Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFile); if (bitmap->GetLastStatus() == Gdiplus::Ok) { if (g_hBitmap != NULL) { DeleteObject(g_hBitmap); } // 获取图像的宽度和高度 int width = bitmap->GetWidth(); int height = bitmap->GetHeight(); // 创建与图像大小相匹配的内存设备上下文 HDC hdcScreen = GetDC(NULL); HDC hdcMem = CreateCompatibleDC(hdcScreen); g_hBitmap = CreateCompatibleBitmap(hdcScreen, width, height); SelectObject(hdcMem, g_hBitmap); // 使用GDI+将图像绘制到内存设备上下文 Gdiplus::Graphics graphics(hdcMem); graphics.DrawImage(bitmap, 0, 0, width, height); // 释放资源 DeleteDC(hdcMem); ReleaseDC(NULL, hdcScreen); SendMessage(g_hImage, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)g_hBitmap); EnableWindow(g_hButtonSave, TRUE); } delete bitmap; } } // ... ``` 请注意,我们添加了一些代码来处理图像的宽度和高度,并创建与图像大小相匹配的内存设备上下文。这样可以确保在加载图像时保持其原始大小。 再次感谢您的指出,如果还有其他问题,请随时提问!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值