//速度有点慢 你可用FastBmp
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
PaintBox1: TPaintBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure PaintBox1Paint(Sender: TObject);
procedure Memo1Change(Sender: TObject);
private
bmp: TBitmap;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
DoubleBuffered := true;
bmp := TBitmap.Create;
bmp.Width := 200;
bmp.Height := 255;
with bmp.Canvas do
begin
for i := 0 to 255 do
begin
Pen.Color := rgb(i, i, i);
MoveTo(0, i);
lineTo(200, i);
end;
end;
Image1.Picture.Bitmap.Assign(bmp);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
freeandnil(bmp)
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
tempbmp, temp2: TBitmap;
i, j: integer;
c: Tcolor;
begin
tempbmp := TBitmap.Create;
tempbmp.Width := Memo1.Width - 10;
tempbmp.Height := Memo1.Height - 10;
tempbmp.Transparent := true;
Memo1.PaintTo(tempbmp.Canvas, -1, -1);
temp2 := TBitmap.Create;
temp2.Assign(bmp);
for i := 0 to tempbmp.Width do
for j := 0 to tempbmp.Height do
if tempbmp.Canvas.Pixels[i, j] = clblack then
begin
c := temp2.Canvas.Pixels[i, j];
if c > $888888 then
temp2.Canvas.Pixels[i, j] := temp2.Canvas.Pixels[i, j] - $888888
else
temp2.Canvas.Pixels[i, j] := temp2.Canvas.Pixels[i, j] + $888888
end;
PaintBox1.Canvas.Draw(1, 1, temp2);
FreeAndNil(tempbmp);
FreeAndNil(temp2);
end;
procedure TForm1.Memo1Change(Sender: TObject);
begin
PaintBox1.Repaint;
end;
end.