C++生成器透明位图覆盖画布
C++ builder transparent bitmaps cover the canvas
在TForm
的OnPaint
事件中,我想绘制不覆盖背景或其他绘制对象的位图,因为它们具有透明的部分。
如果我在图像上绘制图像,它可以工作。
但是当我在表单的Canvas
上绘制时,它不起作用:图像的白色部分应该是透明的,用白色正方形覆盖画布的其他对象。
Canvas->CopyMode = cmMergePaint ;
Graphics::TBitmap * Image=new Graphics::TBitmap();
Image->Transparent = true;
MainForm->Images->GetBitmap(14, Image);
Canvas->Draw(10,10,Image;
MainForm->Images->GetBitmap(0, Image);
Canvas->Draw(15,15,Image);
更新
当我使用MainForm->Images->Draw(Image->Canvas...)
在图像上绘制时,我得到一个透明的正方形,里面什么都没有,我可以在其他组件上移动。
当我使用 MainForm->Images->GetBitmap(ImgIndex[HisType]+Rotation, Image)
绘制时,我在表单上获得了正确的条纹图像,但没有透明度,即它的白色部分覆盖了其他组件。
当MainForm->Images->Draw(Canvas, X, Y, ImgIndex[HisType]+Rotation, dsTransparent, itImage);
完成这项工作时,我需要根据 Size 变量为此组件划线。
TRect DstRect(X,Y, X+32 + ( 1 - Rotation ) * 32 * Size, Y+32 + Rotation * 32 * Size);
Graphics::TBitmap * Image=new Graphics::TBitmap();
Image->Transparent=true;
//MainForm->Images->GetBitmap(ImgIndex[HisType]+Rotation, Image);
MainForm->Images->Draw(Image->Canvas, 0, 0, ImgIndex[HisType]+Rotation, dsTransparent, itImage);
Canvas->StretchDraw(DstRect, Image);
delete Image;
//MainForm->Images->Draw(Canvas, X, Y, ImgIndex[HisType]+Rotation, dsTransparent, itImage);
请改用Images->Draw()
,让TImageList
为您处理绘图:
MainForm->Images->Draw(Canvas, 10, 10, 14, dsTransparent, itImage);
MainForm->Images->Draw(Canvas, 15, 15, 0, dsTransparent, itImage);
找到了
解决方案,感谢雷米。我们必须首先用一种颜色填充新创建的位图,不要让它为空,以便透明度工作......
Size=1; //debug
TRect DstRect(X,Y, X+32 + ( 1 - Rotation ) * 32 * Size, Y+32 + Rotation * 32 * Size);
Graphics::TBitmap * Image=new Graphics::TBitmap();
Image->Width = 32;
Image->Height = 32;
Image->Canvas->FillRect(Rect(0,0,32,32));
MainForm->Images->GetBitmap(ImgIndex[HisType]+Rotation, Image);
//MainForm->Images->Draw(Image->Canvas, 0, 0, ImgIndex[HisType]+Rotation, dsTransparent, itImage);
Image->Canvas->Pen->Color = clRed;
Image->Canvas->MoveTo( 3, 3 );
Image->Canvas->LineTo( 29, 29 );
Image->Transparent=true;
Canvas->StretchDraw(DstRect, Image);
delete Image;
相关文章:
- C / C++ 移位/偏移/向左或向右移动位图?
- 如何在快板的屏幕中显示子位图的绘制?
- CreateDIBSection为同一图像返回不一致的位图位值
- C++ 位图中的 ttc 字体
- 使用 GDI+ 旋转位图,然后转换为 HDC
- 难以从 CImageList 设置菜单项位图
- 如何将位图拉伸到父面板(wxWidgets 自定义)
- 如何使用 freetype2 访问单色位图中的像素状态
- 将位图 (bmp) 转换为具有透明度的 png (Windows c++)
- 安卓工作室 |CPP 文件错误错误: 位图库中对"AndroidBitmap_unlockPixels"的未定义引用
- 位图到垫子/2D 数组
- Gdiplus位图没有Alpha通道
- 如何从路径字符串加载Gdiplus::位图
- 在C++中使用Gdiplus创建透明位图
- 用C++压缩内存中的位图
- C++gdi::内存中的位图到PNG图像
- LoadImage 函数不适用于 ImageMagick 创建的位图图像
- (位图)LoadImage() 返回 NULL,GetLastError() 返回 0
- 将Qt qml文件转换为位图图像
- C++生成器透明位图覆盖画布