Jump to content
Martin Liddle

Display of bmp and jpeg images is poorer quality in Windows 11

Recommended Posts

I have a VCL Delphi app that displays bmp or jpeg images on reports as headers and footers using stretchdraw.  This code that has worked well for 22 years but on two different Windows 11 computers the quality of the images when displayed on screen is much poorer than on earlier versions of Windows.  I have attached two screen grabs, note that the images will only be about 25mm height when displayed.  The results are the same if the code is compiled on Windows 10 using Delphi 10.3.1 or on Windows 11 using Delphi 10.4.  When printed the images are identical for all versions of Windows.  My googling skills are obviously failing me as I thought this would be a common problem but I have so far only found one reference to a vaguely similar problem.  I am guessing there is some graphics setting in Windows 11 that needs tweaking but I would also be interested if there are changes to the way the images are drawn that might help.  

Windows10.JPG

Windows11.png

Share this post


Link to post

I think that you need to say more about:

  • what components/classes used to load/show the pictures?
  • what components/classes used to print it?
  • what "your" code used with above?

Share this post


Link to post

Is one or both of the computers have screen scaling other than 100%?

What is the original size of the image and what is the size of the rectangle where you display it?

 

Share this post


Link to post
44 minutes ago, FPiette said:

Is one or both of the computers have screen scaling other than 100%?

What is the original size of the image and what is the size of the rectangle where you display it?

 

I currently only have details for one of the computers, a Lenovo Thinkpad E15 gen 2 with : the recommended setting for screen scaling is 125% which is what I was using; I had already experimented with setting screen scaling to 100% and the problem remains.  The image is 8" x 0.633" (203.2mm x 16.1mm) with a 300 dpi resolution.  The size of the display rectangle can vary but is typically 7.5" x  0.6" (190.5mm x 15.4mm).

Share this post


Link to post
52 minutes ago, programmerdelphi2k said:

I think that you need to say more about:

  • what components/classes used to load/show the pictures?
  • what components/classes used to print it?
  • what "your" code used with above?

The code used to show the pictures and to print the pictures is the same; just the dpi is changed.

Code to load images:

 

Procedure GetALogo(EventNumber:Integer;AFileName:String;LogoNumber:Integer;Var HasLoaded:Boolean);
Var TempFileName:String;
Begin
 HasLoaded:=True;
 TempFileName:=WorkingDirectory+AFileName+IntToStr(EventNumber);
 If FileExists(TempFileName+'.bmp') then Logo[LogoNumber].LoadFromFile(TempFileName+'.bmp')
 Else If FileExists(TempFileName+'.jpg') then
  Begin
   JpegLogo[LogoNumber].LoadFromFile(TempFileName+'.jpg');
   Logo[LogoNumber].Assign(JpegLogo[LogoNumber]);
  End
 Else
  Begin
   TempFileName:=WorkingDirectory+AFileName;
   If FileExists(TempFileName+'.bmp') then Logo[LogoNumber].LoadFromFile(TempFileName+'.bmp')
   Else If FileExists(TempFileName+'.jpg') then
    Begin
     JpegLogo[LogoNumber].LoadFromFile(TempFileName+'.jpg');
     Logo[LogoNumber].Assign(JpegLogo[LogoNumber]);
    End
   Else
    Begin
     HasLoaded:=False;
     Logo[LogoNumber].Free;
     Logo[LogoNumber]:=TBitMap.Create;
    End;
  End;
End;
 

Code to show an image:

 

Procedure ShowLogoNew(PageProps:TPageProps;ABitMap:TBitMap;LeftSpace,TopSpace,WidthSpace,DepthSpace:Real;
                 HorizAlign,VertAlign:TLogoAlignment;Var ActualBottom:Real);
Const MLogo=0.018;
Var ALeft,ATop,ARight,ABottom,ExtraMargin:Integer;
    ImgAspectRatio,SpaceAspectRatio:Real;
    ARect:Trect;
Begin
 With ABitMap, PageProps Do
  Begin
   If ABitMap.Height*ABitMap.Width>0 then
    Begin
     ALeft:=Round((LeftSpace+MLogo)*HPix);
     ATop:= Round((TopSpace+MLogo)*VPix);
     ImgAspectRatio:=Height/Width;
     SpaceAspectRatio:=DepthSpace/WidthSpace;
     If ImgAspectRatio>SpaceAspectRatio then
      Begin
       ExtraMargin:=Round((WidthSpace-2*MLogo)*HPix-(DepthSpace-2*MLogo)*VPix/ImgAspectRatio);
       Case HorizAlign of
        laLeft    : (*ALeft:=ALeft*);
        laHCentre : ALeft:=ALeft+ExtraMargin div 2;
        laRight   : ALeft:=ALeft+ExtraMargin;
        Else ;
       End;
      ARight:=ALeft+Round((DepthSpace-2*Mlogo)*HPix/ImgAspectRatio);
      ABottom:=ATop+Round((DepthSpace-2*Mlogo)*VPix);
      End
     Else
      Begin
       ExtraMargin:=Round((DepthSpace-2*MLogo)*VPix-(WidthSpace-2*MLogo)*HPix*ImgAspectRatio);
       Case VertAlign of
         laTop : (*ATop:=ATop*);
         laVCentre : ATop:=ATop+ExtraMargin div 2;
         laBottom  : ATop:=ATop+ExtraMargin;
        End;
       ARight:=ALeft+Round((WidthSpace-2*Mlogo)*HPix);
       ABottom:=ATop+Round((WidthSpace-2*Mlogo)*VPix*ImgAspectRatio);
      End;
     ARect:=Rect(ALeft,ATop,ARight,ABottom);
     ActualBottom:=ABottom/VPix;
     ACanvas.StretchDraw(ARect,ABitMap);
    End;  (*If AbitMap.Height*ABitMap.Width>0*)
  End;
End; (*ShowLogoNew*)
 

Share this post


Link to post
30 minutes ago, Martin Liddle said:

I currently only have details for one of the computers, a Lenovo Thinkpad E15 gen 2 with : the recommended setting for screen scaling is 125% which is what I was using; I had already experimented with setting screen scaling to 100% and the problem remains.  The image is 8" x 0.633" (203.2mm x 16.1mm) with a 300 dpi resolution.  The size of the display rectangle can vary but is typically 7.5" x  0.6" (190.5mm x 15.4mm).

The size need to be expressed in pixel. And speaking about computer, please tell the OS! You have two computers with two different OS and we don't know which is which.

Try to manage that the image are NOT rescaled for display. This is how you get best looking.

Share this post


Link to post

here my sample, simple to load... BMP or JPEG or GIF or any other types allowed on TPictures class!!!

Quote

  {TWICImage}
  { TWICImage encapsulates the Microsoft Windows Imaging Component, allowing loading image formats that have been registered through WIC. Supports:
    BMP, GIF, ICO, JPEG, PNG, TIFF, and Windows Media Photo.
    Requires Windows XP SP2 with .NET 3.0.}
 

see on RAD sources: Vcl.Graphics.pas, line +/-5646 (RAD 11.2) by:  constructor TFileFormatsList.Create;  list of extentions files allowed!!!

uses
  GIFImg;

procedure TForm1.Button1Click(Sender: TObject);
var
  Pic: TPicture;
begin
  Pic := TPicture.Create;
  try
    Pic.LoadFromFile('d:\ABitmap.bmp');
    Image1.Picture.Assign(Pic);
    //
    Pic.LoadFromFile('d:\AJPEG.jpeg');
    Image2.Picture.Assign(Pic);
    //
    Pic.LoadFromFile('d:\AGIF.gif');
    Image3.Picture.Assign(Pic);
  finally
    Pic.Free;
  end;
end;

image.thumb.png.a79c3b20148a8cbec55299974bdeb2e0.png   

Edited by programmerdelphi2k

Share this post


Link to post
1 hour ago, programmerdelphi2k said:

I think that your problem can be on: converting your JPEG to BMP, or inverse:

Why do you think that the conversion produce different results when running the same executable on Windows 10 and Windows 11?

Share this post


Link to post
5 hours ago, FPiette said:

The size need to be expressed in pixel. And speaking about computer, please tell the OS! You have two computers with two different OS and we don't know which is which.

Try to manage that the image are NOT rescaled for display. This is how you get best looking.

I apologise; this is the first time I have posted on this forum; most forums I have used show the file name of an upload.  The top image is Windows 10 and the bottom image Windows 11.  I agree that not rescaling will produce the best image but 20 years of experience with this software has convinced me that the images are good enough for the purpose using stretchdraw.

Edited by Martin Liddle

Share this post


Link to post
2 hours ago, FPiette said:

The code you show is not that useful. Preferably Show a minimal, complete, verifiable and reproducible example (See https://stackoverflow.com/help/minimal-reproducible-example). to know exactly what that means). With such example, we will be able to reproduce your problem, understand it and try to solve it.

There would be a significant amount of work to strip out the necessary code.  If I can't find a solution then I will do that but I don't want to commit the time to do it until I have exhausted other avenues.  I was hoping I might find someone here who had seen a similar problem and found a solution.

Share this post


Link to post
On 12/3/2022 at 6:55 PM, Martin Liddle said:

There would be a significant amount of work to strip out the necessary code.

You should start from scratch. Trust me, frequently when doing so, people find themself the error they made or can't reproduce their own issue. Then then fix themself their code in their larger application based on the small example.

  • Like 1
  • Thanks 1

Share this post


Link to post
On 12/5/2022 at 8:13 AM, Fr0sT.Brutal said:

First of all, you have alpha channel converted badly in the 2nd image

Thank you that is an interesting observation; any thoughts on why that is only happening on Windows 11?

Share this post


Link to post
14 hours ago, Martin Liddle said:

Thank you that is an interesting observation; any thoughts on why that is only happening on Windows 11?

No idea, probably some defaults changed?

Share this post


Link to post

I have now found time to have another look at this problem.  The issue appears to be that the PIxelFormat of the canvas was originally set to pf16bit but 9 years ago was reduced to pf8bit to save memory.  This worked satisfactorily on all Windows version up to and including Windows 10.  Changing the PixelFormat to pf16bit fixes the problem on Windows 11.  Thank you to all who contributed to this thread.

  • Thanks 1

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

×