A
ANTIDEAD
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
private
procedure drawtransparent(thandle:hdc;x,y:integer;s:tbitmap;trcol:tcolor);
protected
Image1: TImage;
procedure FormActivate(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
begin
drawtransparent(canvas.handle,image1.width,0,image1.picture.bitmap,clblack);
end;
procedure drawtransparent(thandle:hdc;x,y:integer;s:tbitmap;trcol:tcolor);
var
bmpxor,bmpand,bmpinvand,bmptarget:tbitmap;
oldcol:longint;
begin
try
bmpand:=tbitmap.create;
bmpand.width:=S.width;
bmpand.height:=s.height;
bmpand.monochrome:=true;
oldcol:=setbkcolor(s.canvas.handle,colortorgb(trcol));
bitblt(bmpand.Canvas.handle,0,0,s.width,s.height,s.canvas.handle,0,0,srccopy);
setbkcolor(s.canvas.handle,oldcol);
bmpinvand:=tbitmap.create;
bmpinvand.width:=S.width;
bmpinvand.height:=s.height;
bmpand.monochrome:=true;
bitblt(bmpinvand.Canvas.handle,0,0,s.width,s.height,bmpand.canvas.handle,0,0,notsrccopy);
bmpxor:=tbitmap.create;
bmpxor.width:=S.width;
bmpxor.height:=s.height;
bitblt(bmpxor.Canvas.handle,0,0,s.width,s.height,bmpinvand.canvas.handle,0,0,srccopy);
bitblt(bmpxor.Canvas.handle,0,0,s.width,s.height,bmpinvand.canvas.handle,0,0,srcand);
bmptarget:=tbitmap.create;
bmptarget.width:=S.width;
bmptarget.height:=s.height;
bitblt(bmptarget.Canvas.handle,0,0,s.width,s.height,thandle,0,0,srccopy);
bitblt(bmptarget.Canvas.handle,0,0,s.width,s.height,bmpand.canvas.handle,0,0,srcand);
bitblt(bmptarget.Canvas.handle,0,0,s.width,s.height,bmpxor.canvas.handle,0,0,srcinvert);
bitblt(thandle,x,y,s.width,s.height,bmptarget.canvas.handle,0,0,srccopy);
finally
bmpxor.free;
bmpand.free;
bmpinvand.free;
bmptarget.free;
end;
end;
end.
怎样解决!
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
private
procedure drawtransparent(thandle:hdc;x,y:integer;s:tbitmap;trcol:tcolor);
protected
Image1: TImage;
procedure FormActivate(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
begin
drawtransparent(canvas.handle,image1.width,0,image1.picture.bitmap,clblack);
end;
procedure drawtransparent(thandle:hdc;x,y:integer;s:tbitmap;trcol:tcolor);
var
bmpxor,bmpand,bmpinvand,bmptarget:tbitmap;
oldcol:longint;
begin
try
bmpand:=tbitmap.create;
bmpand.width:=S.width;
bmpand.height:=s.height;
bmpand.monochrome:=true;
oldcol:=setbkcolor(s.canvas.handle,colortorgb(trcol));
bitblt(bmpand.Canvas.handle,0,0,s.width,s.height,s.canvas.handle,0,0,srccopy);
setbkcolor(s.canvas.handle,oldcol);
bmpinvand:=tbitmap.create;
bmpinvand.width:=S.width;
bmpinvand.height:=s.height;
bmpand.monochrome:=true;
bitblt(bmpinvand.Canvas.handle,0,0,s.width,s.height,bmpand.canvas.handle,0,0,notsrccopy);
bmpxor:=tbitmap.create;
bmpxor.width:=S.width;
bmpxor.height:=s.height;
bitblt(bmpxor.Canvas.handle,0,0,s.width,s.height,bmpinvand.canvas.handle,0,0,srccopy);
bitblt(bmpxor.Canvas.handle,0,0,s.width,s.height,bmpinvand.canvas.handle,0,0,srcand);
bmptarget:=tbitmap.create;
bmptarget.width:=S.width;
bmptarget.height:=s.height;
bitblt(bmptarget.Canvas.handle,0,0,s.width,s.height,thandle,0,0,srccopy);
bitblt(bmptarget.Canvas.handle,0,0,s.width,s.height,bmpand.canvas.handle,0,0,srcand);
bitblt(bmptarget.Canvas.handle,0,0,s.width,s.height,bmpxor.canvas.handle,0,0,srcinvert);
bitblt(thandle,x,y,s.width,s.height,bmptarget.canvas.handle,0,0,srccopy);
finally
bmpxor.free;
bmpand.free;
bmpinvand.free;
bmptarget.free;
end;
end;
end.
怎样解决!