Recent

Author Topic: load and stretch a bmp  (Read 2180 times)

elcomportal

  • New Member
  • *
  • Posts: 16
load and stretch a bmp
« on: March 30, 2018, 05:31:40 pm »
Hi,
i want to simulate a LED matrix. the matrix have a size of 60 x x60 LEDs. So i want to load an image in a TBitmap, shrink it to 60 x 60 pixels and then i want to stretch it to an TImage with a size of 600 x 600 pixels. Then every pixel of the image will show as a square pad of 10 x 10 pixels. That work.
Now i want to increment the pixels of the matrix by clicking on speedbutton13. But with every click the image grows (it's okay), but also the pixelsize grows also, but it have to be every time 10 x 10 pixels. Whats my mistake?
Here is the code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton13Click(Sender: TObject);
  2. var
  3.   F: TextFile;
  4.   S: string;
  5.  
  6.   sr: tsearchrec;
  7.   datDatei: file of byte;
  8.   chrZeichen: byte;
  9. begin
  10.    led_anzahl_zeile:=led_anzahl_zeile + 1;
  11.    bildgroesse :=bildgroesse + raster;
  12.    videocanvas.width := led_anzahl_zeile * raster;
  13.    videocanvas.height := led_anzahl_zeile * raster;
  14.    label1.caption:=LeftPad(trackbar1.position);
  15.    if FindFirst('d://mdf/projects/kosmetikstudio_zarriess/temp/'+LeftPad(trackbar1.position)+'.bmp',faAnyFile,sr) = 0 then
  16.    begin
  17.       if (SR.Attr and faDirectory) = 0 then
  18.       begin
  19.          bmp:=TBitmap.Create;
  20.          vpbmp:=TBitmap.Create;
  21.          videocanvas.Canvas.FillRect(0,0,videocanvas.Width,videocanvas.height);
  22.          bmp.Width:=bildgroesse;
  23.          bmp.Height:=bildgroesse;
  24.          bmp.LoadFromFile('d://mdf/projects/temp/'+sr.name);
  25.          vpbmp.Width:=led_anzahl_zeile ;
  26.          vpbmp.Height:=led_anzahl_zeile;
  27.          vpbmp.Canvas.copyrect(rect(0,0,led_anzahl_zeile,led_anzahl_zeile),bmp.canvas,rect(0,0,bildgroesse,bildgroesse));
  28.          videocanvas.Canvas.StretchDraw(Rect(0,0,videocanvas.height,videocanvas.width),vpbmp);
  29.          label2.caption:=inttostr(bildgroesse)+' '+IntToStr(led_anzahl_zeile)+' '+inttostr(bmp.width)+' '+inttostr(vpbmp.width)+' '+inttostr(0) ;
  30.          videocanvas.Update;
  31.          Application.ProcessMessages;
  32.          bmp.Free;
  33.          vpbmp.Free;
  34.       end;
  35.       FindClose(SR);
  36.    end;
  37.  
  38. end;  
  39.  

circular

  • Hero Member
  • *****
  • Posts: 4194
    • Personal webpage
Re: load and stretch a bmp
« Reply #1 on: April 04, 2018, 10:53:52 am »
I would say you cannot resize bmp like that:
Code: Delphi  [Select][+][-]
  1. bmp.Width:=bildgroesse;
  2.          bmp.Height:=bildgroesse;
because then you do LoadFromFile which sets the Width and Height from the file.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018