【例子介绍】
【相关图片】
【源码结构】
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.stdCtrls,Vcl.ExtCtrls, Data.Bind.EngExt, Vcl.Bind.DBEngExt, System.Rtti, System.Bindings.Outputs, Vcl.Bind.Editors, Data.Bind.Components; type TMain = class(TForm) Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; edtTop: TEdit; edtLeft: TEdit; edtWidth: TEdit; edtHeight: TEdit; Panel1: TPanel; Image1: TImage; BindingsList1: TBindingsList; LinkControlToPropertyTop: TLinkControlToProperty; LinkControlToPropertyLeft: TLinkControlToProperty; LinkControlToPropertyHeight: TLinkControlToProperty; LinkControlToPropertyWidth: TLinkControlToProperty; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure RedrawImage; end; var Main: TMain; implementation {$R *.dfm} procedure TMain.Button1Click(Sender: TObject); begin RedrawImage; end; procedure TMain.FormCreate(Sender: TObject); begin RedrawImage; end; procedure TMain.RedrawImage; var I, J: Integer; Bitmap: TBitmap; begin { create a bitmap picture in the memory } Bitmap := TBitmap.Create; { use the dimensions of the Image1 control } Bitmap.Width := Image1.Width; Bitmap.Height := Image1.Height; { dynamically render a color spectrum } for I := 0 to Bitmap.Width do for J := 0 to Bitmap.Height do Bitmap.Canvas.Pixels[I, J] := RGB(I, J, 128); { assign the bitmap to Image1 } Image1.Picture.Bitmap := Bitmap; { free up used memory } Bitmap.Free; end; end.
评论