Recent

Author Topic: StrechDraw a .bmp File gets pixelated  (Read 943 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
StrechDraw a .bmp File gets pixelated
« on: May 05, 2023, 08:06:52 am »
Hello,

im currently creating a splash screen with this Code:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TfrmIntro.FormShow(Sender: TObject);
  3. var
  4.    temp: TBitmap;
  5. begin
  6.    temp:= TBitmap.Create;
  7.    temp.PixelFormat:= pf32bit;
  8.    temp.LoadFromFile(GetCurrentDir+'\pics\Intro\MyIntro.bmp');
  9.  
  10.    Image1.Picture.Bitmap.SetSize(frmIntro.Width, frmIntro.Height);
  11.    Image1.Picture.Bitmap.Canvas.StretchDraw(Rect(0,0,frmIntro.Width, frmIntro.Height), temp);
  12.  
  13.    temp.free;
  14. end;
  15.  
  16.  

however the Pictures always get pixelated no matter which size the Picture or the Intro Form has. Does anyone have any Idea what i did wrong ?

thanks in advance
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

cdbc

  • Hero Member
  • *****
  • Posts: 1028
    • http://www.cdbc.dk
Re: StrechDraw a .bmp File gets pixelated
« Reply #1 on: May 05, 2023, 09:11:59 am »
Hi
A quick fix for you, would be to fire up OPM and get TBGRABitmap et.al. installed and then use that as your background buffer:
Code: Pascal  [Select][+][-]
  1.  
  2. procedure TfrmIntro.FormShow(Sender: TObject);
  3. var
  4.    temp: TBGRABitmap;
  5. begin
  6.    temp:= TBGRABitmap.Create(GetCurrentDir+'\pics\Intro\MyIntro.bmp');
  7.    temp.PixelFormat:= pf32bit; // <- dunno about this one...
  8.    Image1.Stretch:= true;
  9.    Image1.Picture.Bitmap.SetSize(frmIntro.Width, frmIntro.Height);
  10.    Image1.Picture.Bitmap.Assign(temp);
  11.  
  12.    temp.free;
  13. end;
  14.  
Something like this.
edit: BGRBitmap also sports high quality resampling of pictures  :D
Regards Benny
« Last Edit: May 05, 2023, 09:14:59 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: StrechDraw a .bmp File gets pixelated
« Reply #2 on: May 05, 2023, 10:05:35 am »
however the Pictures always get pixelated no matter which size the Picture or the Intro Form has. Does anyone have any Idea what i did wrong ?
not without the lfm. I suspect that you have some (modified) properties for your TImage.

btw: Why so complicated ? Below some code that shows you which properties for TImage to set.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Image1.Align := alClient;
  4.   Image1.Stretch := True;
  5.   Image1.Picture.LoadFromFile('testpicture-5266x6583.bmp');
  6. end;
  7.  
Ofc. If you wish for the picture to load in the onshow event then that is ok.

The above works ok for me but the quality will degrade if your bmp is a lot smaller than the actual dimensions of the form. Using a bigger picture and down scaling it always provide a better result.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: StrechDraw a .bmp File gets pixelated
« Reply #3 on: May 05, 2023, 10:55:38 am »
The splash screen is the first impression that new users have from your application - I would not make any compromise: display the unscaled image; if it is too large or too small find another one.

To display the unscaled image set the AutoSize of the TImage (which contains the splash image) to true, do not set its Stretch or Proportional to true. And also set the AutoSize of the splash form to true. This way you always have the best quality, and all sizes adjust themselves so that nothing is clipped or left uncovered.

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: StrechDraw a .bmp File gets pixelated
« Reply #4 on: May 05, 2023, 11:04:09 am »
@wp: see picture  :)

btw why does the forum not accept webp image files ? Those are usually much smaller in size

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: StrechDraw a .bmp File gets pixelated
« Reply #5 on: May 05, 2023, 11:32:24 am »
TRon, what do you want to say? That the image is distorted? This is because your code only sets Image.Stretch := true - if you really want to stretch, also set Proportional to true which keeps the aspect ratio of width to height. (https://lazarus-ccr.sourceforge.io/docs/lcl/extctrls/tcustomimage.proportional.html). But as I said, I would not stretch at all, in particular in case of up-scaling.

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: StrechDraw a .bmp File gets pixelated
« Reply #6 on: May 05, 2023, 11:41:44 am »
Sorry, my intention with my post was twofold
1) an image to make the things you warned about visible
2) respond to your solution to circumvent that with a: "cool thumbsup"

Besides that, to show TS how it looks like on my side when using his approach.
« Last Edit: May 05, 2023, 11:43:30 am by TRon »

 

TinyPortal © 2005-2018