c ++从资源视觉工作室加载图像2012年在窗口上绘制

时间:2013-06-06 18:37:34

标签: c++ visual-studio-2012 bitmap resources window

我在2012年视觉工作室加载图片时出现问题:

case WM_PAINT: 
    hBitmap = (HBITMAP)LoadImage(::hInstance, L"apple.jpg", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); // problem??
            PAINTSTRUCT     ps;
            HDC             hdc;
            BITMAP          bitmap;
            HDC             hdcMem;
            HGDIOBJ         oldBitmap;

            hdc = BeginPaint(hWnd, &ps);

            hdcMem = CreateCompatibleDC(hdc);
            oldBitmap = SelectObject(hdcMem, hBitmap);

            GetObject(hBitmap, sizeof(bitmap), &bitmap);
            BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);

            SelectObject(hdcMem, oldBitmap);
            DeleteDC(hdcMem);

            EndPaint(hWnd, &ps);
return 0;

我将图像从桌面拖放到2012年的视觉工作室,但图像没有出现在我的窗口中。

enter image description here

我认为问题是L“apple.jpg”,有没有人没有我做错了什么?

1 个答案:

答案 0 :(得分:1)

问题是“LoadImage”方法不支持JPG图像。它只支持BMP。