HDC hdk;
TRect rect;
//Application->Minimize();
hdk=GetWindowDC(GetDesktopWindow());
GetWindowRect(GetDesktopWindow(),&rect);
Graphics::TBitmap *bmp;
bmp=new Graphics::TBitmap();
bmp->Height=100;
bmp->Width=300;
GetWindowRect(GetDesktopWindow(),&rect);
SetBkMode(bmp->Canvas->Handle,TRANSPARENT);
bmp->Canvas->TextOutA(0,0,"This is a test project!");
bmp->Canvas->Font->Size=18;
BitBlt(hdk,(rect.Width()-bmp->Width)/2,(rect.Height()-bmp->Height)/2,bmp->Width,bmp->Height,bmp->Canvas->Handle,0,0,SRCCOPY);
发现未画的部分并分是无(即透明)而是白色,本来SetBkMode()就是设置Canvas的背景为透明,在窗口内画无问题,而用BitBlt则不行,是不是因为bmp初始为白色,怎么食不使得它为NULL,以前看过一篇关于透明位图,一下找不到了,用其它方式实现也行。
有经典答案我会加分的
9 个解决方案
#1
最简单的方法
Form1->Brush->Style=bsClear;
查询透明可看到更多的方法
Form1->Brush->Style=bsClear;
查询透明可看到更多的方法
#2
使用BrushCopy可实现透明复制Bitmap
另外对桌面的操作是不是烦了点?
直接绘制桌面(已有一Bitmap): HDC dc = ::GetDC(0);
TCanvas *DeskCanvas = new TCanvas();
DeskCanvas->Handle = dc;
DeskCanvas->Brush->Style = bsClear;
DeskCanvas->TextOut(50, 50, "Just a test.");
DeskCanvas->BrushCopy(TRect(100, 100, Bitmap->Width+100, Bitmap->Height+100),
Bitmap,
TRect(0, 0, Bitmap->Width, Bitmap->Height),
Bitmap->Canvas->Pixels[0][0]);
delete DeskCanvas;
::ReleaseDC(0, dc);
另外对桌面的操作是不是烦了点?
直接绘制桌面(已有一Bitmap): HDC dc = ::GetDC(0);
TCanvas *DeskCanvas = new TCanvas();
DeskCanvas->Handle = dc;
DeskCanvas->Brush->Style = bsClear;
DeskCanvas->TextOut(50, 50, "Just a test.");
DeskCanvas->BrushCopy(TRect(100, 100, Bitmap->Width+100, Bitmap->Height+100),
Bitmap,
TRect(0, 0, Bitmap->Width, Bitmap->Height),
Bitmap->Canvas->Pixels[0][0]);
delete DeskCanvas;
::ReleaseDC(0, dc);
#3
SetBkMode只是针对文字输出
你可先把屏幕对应位置的内容复制到bitmap的canvas,再TextOut后再复制回来
你可先把屏幕对应位置的内容复制到bitmap的canvas,再TextOut后再复制回来
#4
BrushCopy?
行吗?
怀疑
行吗?
怀疑
#5
从上面的解答中已得到了答案了,是用在TextOut()前加上Brush->Style=bsClear;实现的。但我对这个属性还是有一点不解:
我在Form中加一一个Panel,在Form的OnCreate()中:
Panel1->Brush->Style=bsClear;
但一点效果都没有。为什么?如果将Form的Brush高为bsClear将会得到一个透明的Form
我在Form中加一一个Panel,在Form的OnCreate()中:
Panel1->Brush->Style=bsClear;
但一点效果都没有。为什么?如果将Form的Brush高为bsClear将会得到一个透明的Form
#6
BrushCopy当然可以了!帮助中说得很明白了:
Copies a portion of a bitmap onto a rectangle on the canvas, replacing one of the colors of the bitmap with the brush of the canvas.
void __fastcall BrushCopy(const Windows::TRect &Dest, TBitmap* Bitmap, const Windows::TRect &Source, TColor Color);
Description
Use BrushCopy to achieve special effects such as making the copied image partially transparent. BrushCopy is provided mainly for backward compatibility. Use a TImageList instead of BrushCopy.
Dest specifies the rectangular portion of the canvas that will receive the copy of the bitmap. Bitmap specifies the graphic to copy from. Source specifies the rectangular area of Bitmap to copy. Color specifies the color in Bitmap to replace with the Brush of the canvas.
To use BrushCopy to make the copied image partially transparent, specify the color of the surface of the canvas (clBackground for example) as the Color of the Brush property, then call BrushCopy.
设置Panel1->Brush->Style的确不管用,可能与TPanel自己的重绘方式有关吧。
Copies a portion of a bitmap onto a rectangle on the canvas, replacing one of the colors of the bitmap with the brush of the canvas.
void __fastcall BrushCopy(const Windows::TRect &Dest, TBitmap* Bitmap, const Windows::TRect &Source, TColor Color);
Description
Use BrushCopy to achieve special effects such as making the copied image partially transparent. BrushCopy is provided mainly for backward compatibility. Use a TImageList instead of BrushCopy.
Dest specifies the rectangular portion of the canvas that will receive the copy of the bitmap. Bitmap specifies the graphic to copy from. Source specifies the rectangular area of Bitmap to copy. Color specifies the color in Bitmap to replace with the Brush of the canvas.
To use BrushCopy to make the copied image partially transparent, specify the color of the surface of the canvas (clBackground for example) as the Color of the Brush property, then call BrushCopy.
设置Panel1->Brush->Style的确不管用,可能与TPanel自己的重绘方式有关吧。
#7
3q
#8
To ddeng(登登) :多谢
#9
关注。。。
#1
最简单的方法
Form1->Brush->Style=bsClear;
查询透明可看到更多的方法
Form1->Brush->Style=bsClear;
查询透明可看到更多的方法
#2
使用BrushCopy可实现透明复制Bitmap
另外对桌面的操作是不是烦了点?
直接绘制桌面(已有一Bitmap): HDC dc = ::GetDC(0);
TCanvas *DeskCanvas = new TCanvas();
DeskCanvas->Handle = dc;
DeskCanvas->Brush->Style = bsClear;
DeskCanvas->TextOut(50, 50, "Just a test.");
DeskCanvas->BrushCopy(TRect(100, 100, Bitmap->Width+100, Bitmap->Height+100),
Bitmap,
TRect(0, 0, Bitmap->Width, Bitmap->Height),
Bitmap->Canvas->Pixels[0][0]);
delete DeskCanvas;
::ReleaseDC(0, dc);
另外对桌面的操作是不是烦了点?
直接绘制桌面(已有一Bitmap): HDC dc = ::GetDC(0);
TCanvas *DeskCanvas = new TCanvas();
DeskCanvas->Handle = dc;
DeskCanvas->Brush->Style = bsClear;
DeskCanvas->TextOut(50, 50, "Just a test.");
DeskCanvas->BrushCopy(TRect(100, 100, Bitmap->Width+100, Bitmap->Height+100),
Bitmap,
TRect(0, 0, Bitmap->Width, Bitmap->Height),
Bitmap->Canvas->Pixels[0][0]);
delete DeskCanvas;
::ReleaseDC(0, dc);
#3
SetBkMode只是针对文字输出
你可先把屏幕对应位置的内容复制到bitmap的canvas,再TextOut后再复制回来
你可先把屏幕对应位置的内容复制到bitmap的canvas,再TextOut后再复制回来
#4
BrushCopy?
行吗?
怀疑
行吗?
怀疑
#5
从上面的解答中已得到了答案了,是用在TextOut()前加上Brush->Style=bsClear;实现的。但我对这个属性还是有一点不解:
我在Form中加一一个Panel,在Form的OnCreate()中:
Panel1->Brush->Style=bsClear;
但一点效果都没有。为什么?如果将Form的Brush高为bsClear将会得到一个透明的Form
我在Form中加一一个Panel,在Form的OnCreate()中:
Panel1->Brush->Style=bsClear;
但一点效果都没有。为什么?如果将Form的Brush高为bsClear将会得到一个透明的Form
#6
BrushCopy当然可以了!帮助中说得很明白了:
Copies a portion of a bitmap onto a rectangle on the canvas, replacing one of the colors of the bitmap with the brush of the canvas.
void __fastcall BrushCopy(const Windows::TRect &Dest, TBitmap* Bitmap, const Windows::TRect &Source, TColor Color);
Description
Use BrushCopy to achieve special effects such as making the copied image partially transparent. BrushCopy is provided mainly for backward compatibility. Use a TImageList instead of BrushCopy.
Dest specifies the rectangular portion of the canvas that will receive the copy of the bitmap. Bitmap specifies the graphic to copy from. Source specifies the rectangular area of Bitmap to copy. Color specifies the color in Bitmap to replace with the Brush of the canvas.
To use BrushCopy to make the copied image partially transparent, specify the color of the surface of the canvas (clBackground for example) as the Color of the Brush property, then call BrushCopy.
设置Panel1->Brush->Style的确不管用,可能与TPanel自己的重绘方式有关吧。
Copies a portion of a bitmap onto a rectangle on the canvas, replacing one of the colors of the bitmap with the brush of the canvas.
void __fastcall BrushCopy(const Windows::TRect &Dest, TBitmap* Bitmap, const Windows::TRect &Source, TColor Color);
Description
Use BrushCopy to achieve special effects such as making the copied image partially transparent. BrushCopy is provided mainly for backward compatibility. Use a TImageList instead of BrushCopy.
Dest specifies the rectangular portion of the canvas that will receive the copy of the bitmap. Bitmap specifies the graphic to copy from. Source specifies the rectangular area of Bitmap to copy. Color specifies the color in Bitmap to replace with the Brush of the canvas.
To use BrushCopy to make the copied image partially transparent, specify the color of the surface of the canvas (clBackground for example) as the Color of the Brush property, then call BrushCopy.
设置Panel1->Brush->Style的确不管用,可能与TPanel自己的重绘方式有关吧。
#7
3q
#8
To ddeng(登登) :多谢
#9
关注。。。