请问:如何把背景为白色或其他单色的图片(jpg或bmp都行)把背景改称透明???(100分)

  • 主题发起人 主题发起人 fgh001
  • 开始时间 开始时间
F

fgh001

Unregistered / Unconfirmed
GUEST, unregistred user!
请问有这样的控件吗???
 
用Delphix挺容易的
 
把Image的Transparent属性设成true
 
可以用DELPHIX轻松的画上你的图象,并且可以实现透明色,DxDraw,DxImageList...
这儿有下载:
http://www.playicq.com/dispdoc.php?t=&id=1428
 
用GDI的话,可以看看我写的这段程序:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure DrawTransparent(t:Tcanvas; x, y:Integer; s:TBitmap; Trcol:Tcolor);
{ Public declarations }
end;

var
Form1: TForm1;

implementation

var bmpXOR, bmpAND, bmpINVAND, bmpTarget:Tbitmap;
oldcol:longint;

{$R *.DFM}

procedure TForm1.DrawTransparent;
begin
BitBlt(bmpTarget.canvas.handle, 0, 0, s.width, s.height, t.handle, x, y, 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, SRCPAINT);
BitBlt(t.handle, x, y, s.width, s.height, bmpTarget.canvas.handle, 0, 0, SRCCOPY);
end;

procedure TForm1.Button1Click(Sender: TObject);
var s, b:TBitmap;
st, et:TSystemtime;
begin
s:=TBitmap.Create;
b:=TBitmap.Create;
b.LoadFromFile('test2.bmp');
Form1.Canvas.Draw(0, 0, b);
s.LoadFromFile('test3.bmp');

bmpAND:=Tbitmap.Create;
bmpAND.Width:=s.Width;
bmpAND.Height:=s.Height;
bmpAND.Monochrome:=true;
oldcol:=SetBkColor(s.canvas.handle, colortoRGB(s.Canvas.Pixels[0, 0]));
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;
bmpINVAND.Monochrome:=true;
BitBlt(bmpINVAND.Canvas.Handle, 0, 0, s.Width, s.Height, s.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, s.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;

button1.Enabled:=false;
GetSystemtime(st);
Form1.Canvas.Draw(0, 0, b);
DrawTransparent(Form1.Canvas, 50, 50, s, s.Canvas.Pixels[0, 0]);
GetSystemtime(et);
button1.Enabled:=true;
button1.SetFocus;
form1.Canvas.Font.Color:=clYellow;
form1.Canvas.Font.Size:=12;
form1.Canvas.Brush.Style:=bsClear;
form1.Canvas.TextOut(50, 300, 'Elapse Time: '+inttostr((et.wSecond-st.wSecond)*1000+et.wMilliseconds-st.wMilliseconds));

bmpXOR.Free;
bmpAND.free;
bmpINVAND.Free;
bmpTarget.free;
end;

end.
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部