uses ColorGrd
private
{ Private-Deklarationen }
fBitmap: TBitmap;
fDown: boolean;
//
procedure TForm1.FormCreate(Sender: TObject);
begin
fBitmap:= TBitmap.create;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
fBitmap.free
end;
procedure TForm1.FormResize(Sender: TObject);
begin
fBitmap.width:=Paintbox1.width;
fBitmap.height:=Paintbox1.Height;
end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if fDown then begin
case colorgrid1.ForegroundIndex of
0: fBitmap.Canvas.Pixels[x,y]:=clBlack;
1: fBitmap.Canvas.Pixels[x,y]:=clMaroon;
2: fBitmap.Canvas.Pixels[x,y]:=clGreen;
3: fBitmap.Canvas.Pixels[x,y]:=clOlive;
4: fBitmap.Canvas.Pixels[x,y]:=clNavy;
5: fBitmap.Canvas.Pixels[x,y]:=clPurple;
6: fBitmap.Canvas.Pixels[x,y]:=clTeal;
7: fBitmap.Canvas.Pixels[x,y]:=clSilver;
8: fBitmap.Canvas.Pixels[x,y]:=clGray;
9: fBitmap.Canvas.Pixels[x,y]:=clRed;
10: fBitmap.Canvas.Pixels[x,y]:=clLime;
11: fBitmap.Canvas.Pixels[x,y]:=clYellow;
12: fBitmap.Canvas.Pixels[x,y]:=clBlue;
13: fBitmap.Canvas.Pixels[x,y]:=clFuchsia;
14: fBitmap.Canvas.Pixels[x,y]:=clAqua;
15: fBitmap.Canvas.Pixels[x,y]:=clWhite;
end;
paintbox1paint(sender);
end;
end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
fDown:=true;
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
fDown:=false;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
Paintbox1.Canvas.draw(0,0,fBitmap);
end;
Bitmap Laden :
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.execute then begin
SavePictureDialog1.FileName:=OpenPictureDialog1.FileName;
fBitmap.LoadFromFile(OpenPictureDialog1.FileName);
FormResize(Sender);
Paintbox1.invalidate;
end;
end;
Bitmap Speichern :
procedure TForm1.Button2Click(Sender: TObject);
begin
if SavePictureDialog1.execute then begin
OpenPictureDialog1.FileName:=SavePictureDialog1.FileName;
fBitmap.SaveToFile(SavePictureDialog1.FileName);
end;
end;
Keine Kommentare:
Kommentar veröffentlichen