win32编程中使用两次Bitblt函数显示不了图片

qq_35470791 2016-08-18 12:16:48

HDC hdc, hdcmem, hdcm;
HBITMAP BackGround;
BITMAP bm;
/*******中间省略一堆******/
BackGround = LoadBitmap(hinstance, TEXT("BKG")); //BKG是我的背景图
GetObject(BG.hbm, sizeof(BITMAP), &bm);
上面是共同部分。

当代码是这样时:
SelectObject(hdcmem, BG.hbm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcmem, 0, 0, SRCCOPY);
这样可以显示图片,
可是当代码是这样时:
SelectObject(hdcm, BG.hbm);
BitBlt(hdcmem, 0, 0, bm.bmWidth, bm.bmHeight, hdcm, 0, 0, SRCCOPY);
BitBlt(hdc, 0,0, bm.bmWidth, bm.bmHeight, hdcmem, 0,0, SRCCOPY);
就显示不了图片

后者代码都是参考网络资源的 发现别人这样做都可以 为什么我这样不可以...
为什么
...全文
803 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35470791 2016-08-19
  • 打赏
  • 举报
回复
引用 5 楼 qq_35578084 的回复:
//初始化 HBITMAP hBGbmp; HDC hdc; HDC hMemDC; HDC hBGDC; hdc=GetDC(hWnd);//hWnd是窗口句柄 hMemDC=CreateCompatibleDC(hdc); hBGDC=CreateCompatibleDC(hdc); hBGbmp=(HBITMAP)LoadImage(NULL, L"BKG", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE|LR_DEFAULTSIZE); SelectObject(hBGDC,hBGbmp); DeleteObject(hBGbmp); //画图开始 BitBlt(hMemDC, 0,0, W,H, hBGDC, 0,0, SRCCOPY); BitBlt(hdc, 0,0, W,H, hMemDC, 0,0, SRCCOPY); //释放资源 DeleteDC(hMemDC); DeleteDC(hBGDC); ReleaseDC(hdc,hWnd);
对就是这样两次BitBlt贴图 但是发现我这样不行
赵4老师 2016-08-19
  • 打赏
  • 举报
回复
Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError.
qq_35578084 2016-08-19
  • 打赏
  • 举报
回复
楼主根本没用CreateCompatibleDC来创建兼容内存DC,所以BitBlt会无法复制
赵4老师 2016-08-18
  • 打赏
  • 举报
回复
BitBlt The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context. BOOL BitBlt( HDC hdcDest, // handle to destination device context int nXDest, // x-coordinate of destination rectangle's upper-left // corner int nYDest, // y-coordinate of destination rectangle's upper-left // corner int nWidth, // width of destination rectangle int nHeight, // height of destination rectangle HDC hdcSrc, // handle to source device context int nXSrc, // x-coordinate of source rectangle's upper-left // corner int nYSrc, // y-coordinate of source rectangle's upper-left // corner DWORD dwRop // raster operation code ); Parameters hdcDest Handle to the destination device context. nXDest Specifies the logical x-coordinate of the upper-left corner of the destination rectangle. nYDest Specifies the logical y-coordinate of the upper-left corner of the destination rectangle. nWidth Specifies the logical width of the source and destination rectangles. nHeight Specifies the logical height of the source and the destination rectangles. hdcSrc Handle to the source device context. nXSrc Specifies the logical x-coordinate of the upper-left corner of the source rectangle. nYSrc Specifies the logical y-coordinate of the upper-left corner of the source rectangle. dwRop Specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color. The following list shows some common raster operation codes: Value Description BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.) DSTINVERT Inverts the destination rectangle. MERGECOPY Merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator. MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator. NOTSRCCOPY Copies the inverted source rectangle to the destination. NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color. PATCOPY Copies the specified pattern into the destination bitmap. PATINVERT Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator. PATPAINT Combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator. SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator. SRCCOPY Copies the source rectangle directly to the destination rectangle. SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator. SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator. SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator. WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.) Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks If a rotation or shear transformation is in effect in the source device context, BitBlt returns an error. If other transformations exist in the source device context (and a matching transformation is not in effect in the destination device context), the rectangle in the destination device context is stretched, compressed, or rotated as necessary. If the color formats of the source and destination device contexts do not match, the BitBlt function converts the source color format to match the destination format. When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context. Not all devices support the BitBlt function. For more information, see the RC_BITBLT raster capability entry in the GetDeviceCaps function as well as the following functions: MaskBlt, PlgBlt, StretchBlt. BitBlt returns an error if the source and destination device contexts represent different devices. ICM: No color management is performed when blits occur. Windows CE: In Windows CE version 1.0, the dwRop parameter can only be assigned the following values: SRCCOPY SRCAND SRCPAINT SRCINVERT In Windows CE version 2.0, the dwRop parameter can be any ROP3. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Bitmaps Overview, Bitmap Functions
qq_35578084 2016-08-18
  • 打赏
  • 举报
回复
//初始化 HBITMAP hBGbmp; HDC hdc; HDC hMemDC; HDC hBGDC; hdc=GetDC(hWnd);//hWnd是窗口句柄 hMemDC=CreateCompatibleDC(hdc); hBGDC=CreateCompatibleDC(hdc); hBGbmp=(HBITMAP)LoadImage(NULL, L"BKG", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE|LR_DEFAULTSIZE); SelectObject(hBGDC,hBGbmp); DeleteObject(hBGbmp); //画图开始 BitBlt(hMemDC, 0,0, W,H, hBGDC, 0,0, SRCCOPY); BitBlt(hdc, 0,0, W,H, hMemDC, 0,0, SRCCOPY); //释放资源 DeleteDC(hMemDC); DeleteDC(hBGDC); ReleaseDC(hdc,hWnd);
qq_35578084 2016-08-18
  • 打赏
  • 举报
回复
注意函数前的“以带有颜色区分的格式查看复制到剪贴板” 这个跟函数没关系,是复制的时候出现的。
qq_35578084 2016-08-18
  • 打赏
  • 举报
回复
翻译过来是这样:将源设备上下文的位图到此当前设备上下文。 以带有颜色区分的格式查看复制到剪贴板BOOL BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop ); BOOL BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop ); 参数 -------------------------------------------------------------------------------- x 指定目标矩形的左上角的逻辑x坐标。 y 指定目标矩形的左上角的逻辑y坐标。 nWidth 指定宽度(以逻辑单位)的目标矩形和源位图。 nHeight 指定高度(以逻辑单位)目标矩形和源位图。 pSrcDC 设置为标识设备上下文位图要复制的 CDC 对象的指针。 它必须是 NULL,如果 dwRop 指定不包括一个源的光栅操作。 xSrc 指定源位图的左上角的逻辑x坐标。 ySrc 指定源位图的左上角的逻辑y坐标。 dwRop 指定要执行的光栅操作。 光栅操作代码定义GDI如何组合在涉及一个当前画笔、一个可能的源位图和一个目标位图的输出操作的颜色。 为光栅操作代码的列表 dwRop 及其说明的参见。Windows SDK 的 BitBlt 有关完整的光栅操作代码,请参见。Windows SDK的 有关光栅操作代码。 返回值 -------------------------------------------------------------------------------- 非零,如果函数运行成功;否则为0。 备注 -------------------------------------------------------------------------------- 应用程序可以对齐窗口或工作区(以字节为单位)界确保 BitBlt 操作在字节对齐的矩形发生。 (设置 CS_BYTEALIGNWINDOW 或 CS_BYTEALIGNCLIENT 标志,在窗口类别的注册。) 在字节对齐的矩形 BitBlt 操作比在不是对齐的字节的矩形 BitBlt 操作大量express。 如果您要对设备上下文指定选件类样式(如字节对齐,则必须注册窗口选件类而不是依赖于Microsoft基础选件类执行断点。 使用全局函数 AfxRegisterWndClass。 通过使用目标设备上下文,使用源设备上下文,GDI转换 nWidth 和 nHeight,一次一次。 如果发生的区域不匹配,GDI使用Windows StretchBlt 功能根据需要压缩或拉伸源位图。 如果目标、源和模式位图没有相同颜色的格式, BitBlt 函数将源和模式位图匹配为目标。 目标位图的前景色和背景色用于转换。 当 BitBlt 函数转换为单色位图转换为颜色时,它将空白位(1)为与黑色(0位)对前景色。 使用目标设备上下文的前景色和背景色。 若要将颜色为将照片, BitBlt 设置为与背景色设置为白色的像素和设置其他像素黑色。 BitBlt 使用彩色设备上下文的前景色和背景色从彩色转换为将图片。 注意不是所有的设备上下文支持 BitBlt。 若要检查特定设备上下文是否支持 BitBlt,请使用 GetDeviceCaps 成员函数并指定 RASTERCAPS 索引。 示例 -------------------------------------------------------------------------------- 为 CDC::CreateCompatibleDC参见示例。 要求 -------------------------------------------------------------------------------- 头文件位置: afxwin.h 请参见 -------------------------------------------------------------------------------- 参考 CDC 类 层次结构图 CDC::GetDeviceCaps CDC::PatBlt CDC::SetTextColor CDC::StretchBlt StretchDIBits BitBlt
qq_35470791 2016-08-18
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
BitBlt The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context. BOOL BitBlt( HDC hdcDest, // handle to destination device context int nXDest, // x-coordinate of destination rectangle's upper-left // corner int nYDest, // y-coordinate of destination rectangle's upper-left // corner int nWidth, // width of destination rectangle int nHeight, // height of destination rectangle HDC hdcSrc, // handle to source device context int nXSrc, // x-coordinate of source rectangle's upper-left // corner int nYSrc, // y-coordinate of source rectangle's upper-left // corner DWORD dwRop // raster operation code ); Parameters hdcDest Handle to the destination device context. nXDest Specifies the logical x-coordinate of the upper-left corner of the destination rectangle. nYDest Specifies the logical y-coordinate of the upper-left corner of the destination rectangle. nWidth Specifies the logical width of the source and destination rectangles. nHeight Specifies the logical height of the source and the destination rectangles. hdcSrc Handle to the source device context. nXSrc Specifies the logical x-coordinate of the upper-left corner of the source rectangle. nYSrc Specifies the logical y-coordinate of the upper-left corner of the source rectangle. dwRop Specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color. The following list shows some common raster operation codes: Value Description BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.) DSTINVERT Inverts the destination rectangle. MERGECOPY Merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator. MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator. NOTSRCCOPY Copies the inverted source rectangle to the destination. NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color. PATCOPY Copies the specified pattern into the destination bitmap. PATINVERT Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator. PATPAINT Combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator. SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator. SRCCOPY Copies the source rectangle directly to the destination rectangle. SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator. SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator. SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator. WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.) Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks If a rotation or shear transformation is in effect in the source device context, BitBlt returns an error. If other transformations exist in the source device context (and a matching transformation is not in effect in the destination device context), the rectangle in the destination device context is stretched, compressed, or rotated as necessary. If the color formats of the source and destination device contexts do not match, the BitBlt function converts the source color format to match the destination format. When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context. Not all devices support the BitBlt function. For more information, see the RC_BITBLT raster capability entry in the GetDeviceCaps function as well as the following functions: MaskBlt, PlgBlt, StretchBlt. BitBlt returns an error if the source and destination device contexts represent different devices. ICM: No color management is performed when blits occur. Windows CE: In Windows CE version 1.0, the dwRop parameter can only be assigned the following values: SRCCOPY SRCAND SRCPAINT SRCINVERT In Windows CE version 2.0, the dwRop parameter can be any ROP3. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Bitmaps Overview, Bitmap Functions
还是不懂...

5,530

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 模式及实现
社区管理员
  • 模式及实现社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧