Author Topic: Displaying a TImage32  (Read 538 times)

JonBondy

  • New Member
  • *
  • Posts: 38
Displaying a TImage32
« on: July 25, 2026, 11:30:07 pm »
I am sure this is simple, but I cannot get it to work.

I have a TImage32 on my form, called "image".   I have a button which does the following when I click:

  if not OpenDialog.Execute() then exit;
  image.Bitmap.LoadFromFile(Opendialog.FileName);

The image displays, but it is horribly distorted.  See the a screen shot of part of the Good Image and a screen shot of the same part of the Bad Image.  I include the actual full PNG file, in case that will be useful.

Notice that in the Bad Image 1) there are vertical white bars every other column, and 2) the image is duplicated on the right side.  It is almost as if it is grabbing every other pixel on the left and every other other pixel on the right.  The image is in PNG format.

I have tried all of the values for image.ScaleMode, and the displayed images all look the same.  I've used TImage32 on and off for two decades, and I've never had this kind of problem before.

What am I missing?  Lazarus 3.2, Windows 11

Thanks!

Jon

BSaidus

  • Hero Member
  • *****
  • Posts: 670
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Displaying a TImage32
« Reply #1 on: July 26, 2026, 09:10:44 am »
Hello.
Try to make

Image.Stretch := False;
Image.AutoSize := False;

And see.

PS: What is the component you use to have this beautiful GUI ?
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

wp

  • Hero Member
  • *****
  • Posts: 13649
Re: Displaying a TImage32
« Reply #2 on: July 26, 2026, 11:52:53 am »
What is the difference between the "good" and "bad" image files? How were they created? Can you upload the files? IIRC Graphics32 is an optimized library for 32-bpp images. If the input image has a different format, maybe it has problems displaying it correctly.

JonBondy

  • New Member
  • *
  • Posts: 38
Re: Displaying a TImage32
« Reply #3 on: July 26, 2026, 01:37:35 pm »
Responses, in order...

I set Image.AutoSize to False (it was already so).  There is no property called Image.Stretch revealed in the properties of Image, but I set Image.ScaleMode to smNormal (rather than smStretch).  The results are the same as originally reported (bad).  The component is TImage32.

The "good" image is a crop of the full image, using a utility I wrote in Delphi decades ago.  The "bad" image is a screen shot of the image as displayed by the program.  I uploaded the original file as well as the two cropped images.  I would have thought that it would be the job of Image.Bitmap.LoadFromFile to convert any legal PNG format into the correct internal representation.  Clearly the original file is a legal file, because both the OS and my utility can display them correctly.  The problem is within the Lazarus program.

JonBondy

  • New Member
  • *
  • Posts: 38
Re: Displaying a TImage32
« Reply #4 on: July 26, 2026, 02:36:53 pm »
I switched from TImage32 to TImage, and everything is working fine.  Rather than beating my head against the TImage32 wall, I will proceed with TImage.  I chose TImage32 because it offers a 100x higher speed when processing pixels, but that speed increase is not helpful if the image displayed is wrong.

wp

  • Hero Member
  • *****
  • Posts: 13649
Re: Displaying a TImage32
« Reply #5 on: July 26, 2026, 03:40:47 pm »
I meant the image file which you loaded into the TImage32 to find out why TImage32 is not able to display this file correctly in Lazarus.

BSaidus

  • Hero Member
  • *****
  • Posts: 670
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Displaying a TImage32
« Reply #6 on: July 26, 2026, 09:23:23 pm »
Hello, @JonBondy
Thank you, I see that you have problem with TImage32, I asked for the PageControl component.
Is it the standard TPageControl or some other component ?

Thanks in advance.

lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

JonBondy

  • New Member
  • *
  • Posts: 38
Re: Displaying a TImage32
« Reply #7 on: July 28, 2026, 12:02:05 am »
wp: as I have stated repeatedly, the image file that I loaded was included in my original post.  It is the largest of the 3 files, with a name starting with "frame"

BSaidus: I am not using a PageControl component.  I just put the TImage32 onto a TForm.

Zvoni

  • Hero Member
  • *****
  • Posts: 3466
Re: Displaying a TImage32
« Reply #8 on: July 28, 2026, 08:41:07 am »
wp: as I have stated repeatedly, the image file that I loaded was included in my original post.  It is the largest of the 3 files, with a name starting with "frame"
I just looked at its File-Attributes?

Am i reading this correctly? 48 Bitdepth?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

wp

  • Hero Member
  • *****
  • Posts: 13649
Re: Displaying a TImage32
« Reply #9 on: July 28, 2026, 01:01:28 pm »
wp: as I have stated repeatedly, the image file that I loaded was included in my original post.  It is the largest of the 3 files, with a name starting with "frame"
I interpreted this as a screenshot: The clipped text at the top, the tabs as part of the image, the scroll-to-the-right button- they will not work interactively when they are part of the image.

But anyway, I downloaded the image, checked it in my PngExplorer and found that it is a 48bpp image, ideed (as already noted by Zvoni). Installed pl_Graphics32 via OPM - I can reproduce the issue that you report, but I cannot find a unit dedicated to PNG import. Tried to use the version from the maintainers' repository (https://github.com/graphics32/graphics32), but this one does not compile, neither using FPC 3.2.2 nor FPC/trunk.

Loaded the image into a plain-old LCL TImage - perfect (as you already reported). Amazing that the LCL can read 48bpp images correctly!

If TImage is too slow (I doubt the factor 100, though), maybe you should check out BGRABitmap which is another optimized graphics library but written specifically for Lazarus.

 

TinyPortal © 2005-2018