如何开发图标库(100分)

  • 主题发起人 主题发起人 微醉男人
  • 开始时间 开始时间

微醉男人

Unregistered / Unconfirmed
GUEST, unregistred user!
我想请教各位大侠,如何开发出诸如里Protel(电子线路制图)里放入电子元件图形的程序
我现在需要开发一个与此类似的程序,最大的难题是不知怎样建图标库与怎样实现将库里的元图
标利用“拖拉”技术放入并显示到我的主程序中,谢谢!
 
图标可以用ImageList来存嘛.
可以用Image来显示.
拖拉也很简单,主程序的OnDragDrop中添加代码Canvas.Draw(..)
如果你的图标已经拖进去了,
然后还允许改动的话,
那就是undo问题了,这个千堆雪比较在行.
不过他好像在忙倒计时,:)
 
谢谢bubble兄的回答
你用过电子标图吗?
说简单一点就是和WORD里的插入长方形差不多,
在显示图标时只显示其主要部分(WORD里的长方形只显示边框)
也就是说其它的是透明的
这个问题又是如何解决的呢?
大量的这样的显示用Image控件会不会影响系统呢
大量是指个200个图标以上
 
看看这个例子.
别的我就不会了.:) 水平太浅了.可以去问问千堆雪.
{此例子可以完成简单的图像去除背景以及合并,
可以将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:puzzledj@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.
 
后退
顶部