Jump to content
A.M. Hoornweg

TImage (JPG) not scaling, but PNG and BMP DO ???

Recommended Posts

Hello all,

 

does anyone else have the issue that a TImage containing a JPG does not re-size when the form is dragged to a screen with a different resolution?

 

The weird thing: This only happens when the contained picture is a *.JPG.  If the picture is a BMP or PNG then it *does* work OK. 

 

See attached image: The property "Stretch" is set to True in all 3 cases.

 

(Edit) compiler version is Delphi 11.1 Alexandria.

 

 

image_resize.png

Edited by A.M. Hoornweg

Share this post


Link to post

OT: I recommend using TImageCollection and TVirtualImageList. This significantly increases the quality of the images.
I don't know if the problem will solve it.

Share this post


Link to post
1 hour ago, Stano said:

OT: I recommend using TImageCollection and TVirtualImageList. This significantly increases the quality of the images.
I don't know if the problem will solve it.

That's pretty useless - "OT" or not. He's using a TImage.

Share this post


Link to post
2 hours ago, A.M. Hoornweg said:

The weird thing: This only happens when the contained picture is a *.JPG.  If the picture is a BMP or PNG then it *does* work OK. 

Weird indeed.

Can you tell if it's the TImage itself or only the content which isn't being scaled?

Share this post


Link to post
4 minutes ago, Anders Melander said:

That's pretty useless - "OT" or not. He's using a TImage.

I guess he meant TVirtualImage instead of TVirtualImageList.

Share this post


Link to post

It is possible to load a JPG image in original size, or 1/2, 1/4 or 1/8 of original size. Maybe it firsts loads it optimized in, for example, 1/4 of its original size, and later it does not have "pixels enough" to scale up?

Share this post


Link to post
6 minutes ago, Vandrovnik said:

Maybe it firsts loads it optimized in, for example, 1/4 of its original size, and later it does not have "pixels enough" to scale up?

That shouldn't matter. Regardless of the dimensions of the jpeg image, it (or rather the internal TBitmap representing the decoded image) will be stretched to fit the target rect.

 

procedure TJPEGImage.Draw(ACanvas: TCanvas; const Rect: TRect);
begin
  ACanvas.StretchDraw(Rect, Bitmap);
end;

 

Share this post


Link to post
2 hours ago, Uwe Raabe said:
2 hours ago, Anders Melander said:

That's pretty useless - "OT" or not. He's using a TImage.

I guess he meant TVirtualImage instead of TVirtualImageList.

OT because I wrote about image quality. Not about the subject of the question. Uwe is right. I did it with ActionToolBar. I didn't realize the difference.

Share this post


Link to post

OK, this is getting even weirder. 

 

I've placed a tTimer on the form plus an event handler to display the size of the 3 images.  The size of the bitmap is 78x98 pixels in all 3 cases.  

 

procedure TForm25.check(img: timage; lbl: tlabel; fmt:String);
begin
  lbl.Caption:=format('%s %d x %d',[fmt, img.Width, img.height]);
end;

procedure TForm25.Timer1Timer(Sender: TObject);
begin
 check (image1,label1,'JPG');
 check (image2,label2,'BMP');
 check (image3,label3,'PNG');
end;

 

Now look what happens if I drag the form to a high-resolution screen (250% zoom). 

 

The tImage having the JPG did not resize but claims to have done so anyway.

The tImage with the BMP scaled correctly but still returns the unscaled size.

And finally, the tImage with the PNG scaled correctly and returns the scaled size.

 

 

zoom100%.png

zoom250%.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×