TPaintBox,图片最终显示类
类似ios的图形上下文。
procedure TForm1.Button1Click(Sender: TObject);
var
canvas: TCanvas;
pic: TPicture;
map: TBitmap;
i: integer;
color: TColor;
begin
color := RGB(Random(255),Random(255),Random(255));
map := TBitmap.Create;
map.Width := 100;
map.Height := 100;
for i:=0 to 99 do
begin
map.Canvas.MoveTo(0,i);
map.Canvas.Pen.Color := color;
map.Canvas.LineTo(100,i);
end;
PaintBox1.Canvas.Draw(0,0,map);
map.Free;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
wid,hei: integer;
begin
inherited;
bit := TJPEGImage.Create;
bit.LoadFromFile('D:\vcl\timg.jpg');
// Canvas.Draw(0,0,bit);
wid := 100;
hei := wid*bit.Height div bit.Width;
Canvas.StretchDraw(Rect(10,10,wid,hei),bit);
end;