Recent

Author Topic: [SOLVED] image created at runtime doesnt scale  (Read 365 times)

stormfinger

  • New member
  • *
  • Posts: 7
[SOLVED] image created at runtime doesnt scale
« on: January 23, 2021, 04:56:32 pm »
hi
i've stumbled across a problem i have pictures in imagelist. Then i try to resize picture from imagelist in temp image and i show result in picture on the form. but if i put temporary picture on form it works like a charm but if i want to create temporary image at runtime it doesnt work ..can anyone tell me what im missing ?  code is as follows. .with temporary runtime  ..picture is shown but its not resized as it should be. but if i use imgTmp thats on the form it works.


Code: Pascal  [Select][+][-]
  1. TFormCasleSiege = class(TForm)
  2.  private
  3.     procedure setImage(myImage: string);
  4.     znakJeOk:boolean;
  5.     imgTemp2 : TImage;
  6.   public
  7.  
  8.   end;                
  9.  

Code: Pascal  [Select][+][-]
  1. procedure TFormCasleSiege.FormCreate(Sender: TObject);
  2. begin
  3.       imgTemp2 := TImage.Create(self);
  4.       imgTemp2.Canvas.Create();
  5.       imgTemp2.Canvas.CreateBrush();
  6.       imgTemp2.Picture.Create;
  7.       imgTemp2.AutoSize := true;
  8.       imgTemp2.Stretch:=true;
  9.       imgTemp2.StretchInEnabled:=true;
  10.       imgTemp2.StretchOutEnabled:=true;
  11.       imgTemp2.Proportional:=true;
  12.       imgTemp2.KeepOriginXWhenClipped:=true;
  13.       imgTemp2.KeepOriginYWhenClipped:=true;
  14.       imgTemp2.Transparent:=true;
  15.       imgTemp2.Canvas.AutoRedraw:=true;
  16.       imgTemp2.width := 578;
  17.       imgTemp2.Height := 286;
  18.  
  19. end;

Code: Pascal  [Select][+][-]
  1. procedure TFormCasleSiege.setImage(myImage: string);
  2. var destRectKL, destRect: TRect;
  3. begin
  4.    destRectKL.Create(0,0,288,140);
  5.    destRect.Create(0,0,90,139);
  6.    
  7.    ImgList.Draw(imgTemp2.canvas,0,0,0);
  8.    imgTemp2.Canvas.StretchDraw(destRectKL,imgTemp2.Picture.Graphic);
  9.    ImgCastles.Canvas.CopyRect(destRectKL,imgTemp2.Canvas,destRectKL);
  10. end;
« Last Edit: January 29, 2021, 01:58:54 am by stormfinger »

stormfinger

  • New member
  • *
  • Posts: 7
Re: image created at runtime doesnt scale
« Reply #1 on: January 29, 2021, 01:58:13 am »
I found problem. Problem was that i set up width and height after creating canvas. so proper code is as follows:
Code: Pascal  [Select][+][-]
  1.     procedure TFormCasleSiege.FormCreate(Sender: TObject);
  2.     begin
  3.           imgTemp2 := TImage.Create(self);
  4.           imgTemp2.width := 578;
  5.           imgTemp2.Height := 286;
  6.           imgTemp2.Canvas.Create();
  7.           imgTemp2.Canvas.CreateBrush();
  8.           imgTemp2.Picture.Create;
  9.           imgTemp2.AutoSize := true;
  10.           imgTemp2.Stretch:=true;
  11.           imgTemp2.StretchInEnabled:=true;
  12.           imgTemp2.StretchOutEnabled:=true;
  13.           imgTemp2.Proportional:=true;
  14.           imgTemp2.KeepOriginXWhenClipped:=true;
  15.           imgTemp2.KeepOriginYWhenClipped:=true;
  16.           imgTemp2.Transparent:=true;
  17.           imgTemp2.Canvas.AutoRedraw:=true;
  18.     end;

 

TinyPortal © 2005-2018