gpt4 book ai didi

c++ -::TransparentBlt 无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-04 16:18:04 25 4
gpt4 key购买 nike

我正在使用::TransparentBlt 绘制一个 bmp,其透明像素由 Magenta RGB(255, 0, 255) 标记,但是::TransparentBlt 行为不正常,一些不应该透明的像素在结果中是透明的.

我做错了什么?

原始图像:

enter image description here

来自::TransparentBlt 的结果

enter image description here

结果图像中的灰色区域是背景图像,其上原始 bmp 是::TransparentBlt-ed

代码:

LRESULT jItems::paint (  )
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
::GetClientRect ( hwnd , &rect ) ;
hdc = ::BeginPaint ( hwnd , &ps ) ;
HDC dcSkin = ::CreateCompatibleDC ( hdc ); // memory dc for skin
HDC hMemDc = ::CreateCompatibleDC ( hdc ); // memory dc for painting
HBITMAP hmemBmp = ::CreateCompatibleBitmap ( hdc, rect.right - rect.left, rect.bottom - rect.top ); // Create bitmap to draw on
HBITMAP hOldMemBmp = ( HBITMAP ) ::SelectObject ( hMemDc, hmemBmp ); // select memory bitmap in memory dc
HBITMAP hOldSkinBmp = ( HBITMAP ) ::SelectObject ( dcSkin, this->hbitmap ); //select skin bitmap in skin memory dc
::FillRect ( hMemDc, &rect, ::CreateSolidBrush ( backgroundColor ) );
::BitBlt ( hMemDc, 0, 0, rect.right - rect.left,
rect.bottom - rect.top, dcSkin, 0, 0, SRCCOPY ); // Paint Skin on Memory DC
::SelectObject ( dcSkin, bottomEdge ); // select edge bitmap in skin memory dc
::TransparentBlt ( hMemDc, 0, 0, rect.right - rect.left,
rect.bottom - rect.top, dcSkin,
0, 0, 237, 10, RGB ( 255, 0, 255 ) ); // Paint edge on Memory DC
::BitBlt ( hdc, 0, 0, rect.right - rect.left,
rect.bottom - rect.top, hMemDc, 0, 0, SRCCOPY ); // Paint Skin on Window DC
//<<<... DeleteDC will leak memory if it holds a resource, so lets select the old bitmap back in the memory DCs
::SelectObject ( hMemDc, hOldMemBmp ); // select old bitmaps back to their respective DCs before deleting
::SelectObject ( dcSkin, hOldSkinBmp ); // select old bitmaps back to their respective DCs before deleting
::DeleteObject ( hOldSkinBmp );
::DeleteObject ( hOldMemBmp );
::DeleteObject( hmemBmp );
::DeleteDC ( hMemDc );
::DeleteDC ( dcSkin );
::EndPaint ( hwnd , &ps ) ;
return 0;
};

最佳答案

来自TransparentBlt documentation .

If the source and destination rectangles are not the same size, the source bitmap is stretched to match the destination rectangle.

在您对 TransparentBlt 的调用中,目标矩形的大小为 (rect.right - rect.left, rect.bottom - rect.top),源矩形的大小为 (237, 10)。因此位图被拉伸(stretch),您得不到预期的结果。

我想两个尺寸都应该是 (237, 10)。

关于c++ -::TransparentBlt 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20310836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com