PaintBox怎么设置为透明的?

thunderingman 2007-03-22 07:22:50
Image只要把Transparent属性设为true就行了
但PaintBox没有Transparent属性,如何设置为透明呢?
...全文
345 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Y___Y 2007-03-27
  • 打赏
  • 举报
回复
DrawTransparentBitmap就是一函数
CPP文件把这个函数写在前面就行了
调用方法与调用一般api函数一样
thunderingman 2007-03-27
  • 打赏
  • 举报
回复
To Y__Y
能否再说得详细一点呢?
PaintBox是在Form1上,
通过Form1->PaintBox->Canvas->TextOutA(0,0,s);来显示内容
现在想把PaintBox透明,在CPP和H文件分别怎么写上面的代码呢?
谢谢指教
laowang2 2007-03-26
  • 打赏
  • 举报
回复
mark
Y___Y 2007-03-26
  • 打赏
  • 举报
回复
写法DrawTransparentBitmap(PaintBox->Canvas->Handle,图像->Handle,.....);
thunderingman 2007-03-26
  • 打赏
  • 举报
回复
怎么写呢?
PaintBox->DrawTransparentBitmap();
这样吗?
Y___Y 2007-03-22
  • 打赏
  • 举报
回复
该函数摘自MSDN.
图像透明的函数,任何窗体都可以用
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart,
short yStart, COLORREF cTransparentColor)
{
BITMAP bm;
COLORREF cColor;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;

hdcTemp = CreateCompatibleDC(hdc);
SelectObject(hdcTemp, hBitmap); // Select the bitmap

GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device

// to logical points

// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);

// Create a bitmap for each DC. DCs are required for a number of
// GDI functions.

// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)::SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)::SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)::SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)::SelectObject(hdcSave, bmSave);

// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));

// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

// Set the background color of the source DC to the color.
// contained in the parts of the bitmap that should be transparent
cColor = SetBkColor(hdcTemp, cTransparentColor);

// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
SRCCOPY);

// Set the background color of the source DC back to the original
// color.
SetBkColor(hdcTemp, cColor);

// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
NOTSRCCOPY);

// Copy the background of the main DC to the destination.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
SRCCOPY);

// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

// Mask out the transparent colored pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

// Copy the destination to the screen.
BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
SRCCOPY);

// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));

// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}


消除闪烁用Form1->DoubleBuffered=true;就可以了
thunderingman 2007-03-22
  • 打赏
  • 举报
回复
没有DoubleBuffered属性啊
huzhangyou 2007-03-22
  • 打赏
  • 举报
回复
PaintBox: 先让你的图象本身透明
Image : 解决闪烁,在其 Parent 控件上的 DoubleBuffered 设为 True;

这是大富翁上的回答

13,874

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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