
TCard(TGraphicControl)
Private BitMap1:TBitMap; {Used to store a card image}Public procedure SetBitmap(image: TBitmap); ……
procedure TCard.SetBitmap(image: TBitmap); begin bitmap1 := Tbitmap.create(); bitmap1.Assign(image); canvas.draw(0,bitmap1); end;
在表单1按钮单击,我想将图像添加到tcard组件
procedure TForm1.button1Click(Sender: TObject);var image : Tbitmap; jpg: TJpegImage;begin image := TBitmap.create(); jpg := Tjpegimage.Create(); jpg.LoadFromfile(dir+'\pics\backcard.jpg'); image.Assign(jpg); card1.setbitmap(image); card1.Repaint; image.Destroy; jpg.Destroy; end;
当我跑步时,没有任何反应.如何将此图像添加到TCard组件的背景中?
解决方法@H_502_32@ 下面是为TGraphicControl后代设置背景图像的示例,以及使用它的示例(它使用表单的OnCreate中的TBitmap,以及button1Click中的TJpegImage来演示两者).它只需要一个新的空白VCL表单应用程序,其上有一个Tbutton可以启动它.unit Unit1;interfaceuses windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,Jpeg,StdCtrls;type TCard = class(TGraphicControl) private FBackGround: TBitmap; procedure SetBackground(Value: TBitmap); overload; public constructor Create(AOwner: TComponent); overrIDe; destructor Destroy; overrIDe; procedure Paint; overrIDe; published property BackGround: TBitmap read FBackGround write SetBackground; end; TForm1 = class(TForm) button1: Tbutton; procedure FormCreate(Sender: TObject); procedure button1Click(Sender: TObject); private { Private declarations } FCard: TCard; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}{ TCard }constructor TCard.Create(AOwner: TComponent);begin inherited; FBackGround := TBitmap.Create;end;destructor TCard.Destroy;begin FBackground.Free; inherited;end;procedure TCard.Paint;begin inherited; Self.Canvas.StretchDraw(Self.ClIEntRect,FBackGround);end;procedure TCard.SetBackground(Value: TBitmap);begin FBackGround.Assign(Value); //Self.SetBounds(left,top,FBackGround.WIDth,FBackGround.Height); InvalIDate;end;procedure TForm1.button1Click(Sender: TObject);var Image: TJPEGImage; Bmp: TBitmap;begin Image := TJPEGImage.Create; Bmp := TBitmap.Create; try Image.LoadFromfile(PathToSomeJPEGfile); Bmp.Assign(Image); FCard.BackGround := Bmp; finally Bmp.Free; Image.Free; end;end;procedure TForm4.FormCreate(Sender: TObject);var Bmp: TBitmap;begin FCard := TCard.Create(Self); FCard.Parent := Self; Bmp := TBitmap.Create; try // Load a standard image from the backgrounds folder (D2007). Bmp.LoadFromfile('C:\Program files (x86)\Common files\CodeGear Shared\Images\BackGrnd\GREENbar.BMP'); FCard.BackGround := Bmp; finally Bmp.Free; end;end;end. 总结 以上是内存溢出为你收集整理的delphi – 在TgraphicControl中将jpg设置为位图全部内容,希望文章能够帮你解决delphi – 在TgraphicControl中将jpg设置为位图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)