两个代码可以正常单独运行,但是如果要同时放在一个程序中运行的话就体现不出淡出效果了,请问哪位高人能帮我改一下,能使即有淡出的效果,又能使图片背景透明呢?
调用API淡出的代码: AnimateWindow(Form1.Handle,1000,AW_HIDE or AW_BLEND);
下面是后来写出来的图片背景透明的代码(当然对比要明显一点,我试验的图片是白底黑图的):
function CreateRegion(wMask:TBitmap;wColor:TColor;
hControl:THandle):HRGN;
function Tform1.CreateRegion(wMask:TBitmap;wColor:TColor;hControl:Thandle):HRGN;
var
dc,dc_c:HDC;
rgn:HRGN;
x,y:integer;
coord:TPoint;
line:boolean;
color:TColor;//生成图像的区域
begin
dc:=GetWindowDC(hControl);
dc_c:=CreateCompatibleDC(dc);
SelectObject(dc_c,wMask.Handle);//选择对象
BeginPath(dc);
for x:=0 to wMask.Width-1 do
begin
line:=false;
for y:=0 to wMask.Height-1 do
begin
color:=GetPixel(dc_c,x,y);
if not (color=wColor) then
begin
if not line then
begin
line:=true;
coord.X:=x;
coord.Y:=y;
end;
end;
if (color=wColor) or (y=wMask.Height-1) then
begin
if line then
begin
line:=false;
MoveToEx(dc,coord.X,coord.Y,nil);
LineTo(dc,coord.X,Y);
LineTo(dc,coord.X+1,Y);
LineTo(dc,coord.X+1,coord.Y);
CloseFigure(dc);
end;
end;
end;
end;
EndPath(dc);
rgn:=PathToRegion(dc);
ReleaseDC(hControl,dc);
Result:=rgn;
end;
procedure TForm1.FormCreate(Sender: TObject);
//将生成的区域赋给窗体
var
w1:TBitmap;
w2:TColor;
rgn:HRGN;
begin
w1:=TBitmap.Create;
w1.Assign(image1.Picture.Bitmap);
w2:=w1.Canvas.Pixels[0,0];
rgn:=CreateRegion(w1,w2,Handle);
if rgn<>0 then
begin
SetWindowRgn(Handle,rgn,true);
end;
w1.Free;
end;