看看这个例子.
别的我就不会了.
水平太浅了.可以去问问千堆雪.
{此例子可以完成简单的图像去除背景以及合并,
可以将OICQ头像放置到任何位图,如有更加复杂的
譬如羽化操作,您可以自己去深究.
2002.1.19}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, jpeg, ComCtrls,shellapi;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Panel1: TPanel;
Image1: TImage;
Image2: TImage;
Button2: TButton;
Button3: TButton;
Button4: TButton;
OpenDialog1: TOpenDialog;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
UpDown1: TUpDown;
Edit2: TEdit;
UpDown2: TUpDown;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
SaveDialog1: TSaveDialog;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Label5: TLabel;
Label6: TLabel;
procedure DrawTrans(DestCanvas: TCanvas; X,Y: smallint; SrcBitmap:
TBitmap; AColor: TColor);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label5Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BackColor:TColor;
implementation
{$R *.DFM}
procedure Tform1.DrawTrans(DestCanvas: TCanvas; X,Y: smallint; SrcBitmap:
TBitmap; AColor: TColor);
var ANDBitmap, ORBitmap: TBitmap;
CM: TCopyMode;
Src: TRect;
begin
ANDBitmap:= nil;
ORBitmap:= nil;
try
ANDBitmap:= TBitmap.Create;
ORBitmap:= TBitmap.Create;
Src := Bounds(0,0, SrcBitmap.Width, SrcBitmap.Height);
with ORBitmap do begin
Width:= SrcBitmap.Width;
Height:= SrcBitmap.Height;
Canvas.Brush.Color := clBlack;
Canvas.CopyMode := cmSrcCopy;
Canvas.BrushCopy(Src, SrcBitmap, Src, AColor);
end;
with ANDBitmap do begin
Width:= SrcBitmap.Width;
Height:= SrcBitmap.Height;
Canvas.Brush.Color := clWhite;
Canvas.CopyMode := cmSrcInvert;
Canvas.BrushCopy(Src, SrcBitmap, Src, AColor);
end;
with DestCanvas do begin
CM := CopyMode;
CopyMode := cmSrcAnd;
Draw(X,Y, ANDBitmap);
CopyMode := cmSrcPaint;
Draw(X,Y, ORBitmap);
CopyMode := CM;
end;
finally
ANDBitmap.Free;
ORBitmap.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DrawTrans(Image1.Canvas,StrToInt(Edit1.text),StrToInt(Edit2.text),Image2.Picture.Bitmap,BackColor);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Image1.Picture.LoadFromFile(OpenDialog1.filename);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Image2.Picture.LoadFromFile(OpenDialog1.filename);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
Image1.Picture.SaveToFile(SaveDialog1.FileName);
end;
procedure TForm1.Label5Click(Sender: TObject);
begin
ShellExecute(handle,nil,'mailto
uzzledj@263.net',nil,nil,sw_normal);
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit1.Text:=IntToStr(x);
Edit2.Text:=IntToStr(Y);
end;
procedure TForm1.Image1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=false;
if Source=Image2 then
Accept:=true;
end;
procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
x:=x-Image2.Width div 2;
y:=y-Image2.Height div 2;
DrawTrans(Image1.Canvas,x,y,Image2.picture.bitmap,BackColor);
end;
procedure TForm1.Image2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
backColor:=Image2.Canvas.Pixels[x,y];
Panel1.Color:=backColor;
end;
procedure TForm1.Image2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=false;
if Source=Sender then
Accept:=true;
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
Image2.DragMode:=dmAutomatic
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Image2.DragMode:=dmManual;
end;
end.