Page 1 of 1

resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 6:38 am
by Stefan
I set the font size in Windows to 125% so that everything is a bit bigger.
Now I notice that resizeimage() suddenly produces very blurry images.
Is there a solution for this?

Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 7:44 am
by Dirk Geppert
Just a thought: have you activated dpi aware?

Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 7:59 am
by Stefan
Yes

Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 8:07 am
by Fred
Can you post a code ?

Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 8:38 am
by Stefan

Code: Select all



Declare CopyAndReduceImageProportional(Image, max_x, max_y)
Declare ReduceImageProportional(Image, max_x, max_y)
Declare Loading(Type, Filename$,ObjectId)
Declare LoadingError(Type, Filename$, ObjectId)
Declare Main()

BindEvent(#PB_Event_Loading,      @Loading())

BindEvent(#PB_Event_LoadingError, @LoadingError())

Enumeration
  #window
  #pic
  #gadget1
  #gadget2
  
EndEnumeration

main()
Procedure Main()
  
  Protected  pic,gadget1
  
  OpenWindow(#window,0,0,1000,600,"Test")
  
  
  LoadImage(#pic,"https://doko-lounge.de/bilder/karten/lounge_grau/3.png")
  
  
  ImageGadget(#gadget1,10,10,10,10,0)
  ImageGadget(#gadget2,10,100,10,10,0)
  
  
  
EndProcedure


Procedure Loading(Type, Filename$,ObjectId)
  
  Protected  pic
  
  If ObjectId=#pic
    Debug Filename$
    SetGadgetState(#gadget1,ImageID(#pic))
    ResizeGadget(#gadget1,#PB_Ignore,#PB_Ignore,ImageWidth(#pic),ImageHeight(#pic))
    
    pic=CopyAndReduceImageProportional(#pic,100,100)
    SetGadgetState(#gadget2,ImageID(pic))
    
    ResizeGadget(#gadget2,GadgetX(#gadget1)+GadgetWidth(#gadget1)+30,#PB_Ignore,ImageWidth(pic),ImageHeight(pic))
    
    If IsImage(pic)
      FreeImage(pic)
    EndIf
    
    
  EndIf
  
  
EndProcedure




Procedure LoadingError(Type, Filename$, ObjectId)
  
   Debug "Loadingerror: "+Filename$
  
  
EndProcedure


Procedure.i CopyAndReduceImageProportional(Image, max_x, max_y)
  
  
  
  If IsImage(image)=0
    ProcedureReturn
  EndIf
  
  Protected i = CopyImage(Image, #PB_Any)
  ReduceImageProportional(i, max_x, max_y)
  ProcedureReturn i
  
  
  
EndProcedure

Procedure ReduceImageProportional(Image, max_x, max_y)
  
  
  If IsImage(image)=0
    ProcedureReturn
  EndIf
  
  
  
  
  If max_x >= ImageWidth(Image) And max_y >= ImageHeight(Image)
    ; Das Bild ist klein genug
    ProcedureReturn
  EndIf
  If max_x * ImageHeight(Image) < max_y * ImageWidth(Image)
    ; entspricht max_x / max_y < width / height
    ; Das heißt beim Skalieren wird die Breite auf max_x skaliert, aber die Höhe wird kleiner als max_y
    ; max_y wird so gesetzt dass gilt: max_y / max_x = Höhe / Breite
    ; also das Verhältnis Höhe / Breite bleibt gleich
    max_y = max_x * ImageHeight(Image) / ImageWidth(Image)
  Else
    max_x = max_y * ImageWidth(Image) / ImageHeight(Image)
  EndIf
  ResizeImage(Image, max_x, max_y)
EndProcedure


Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 8:57 am
by Fred
IMHO, you just need an higher resolution image and scale it down instead of scale up, so you cover the higher DPI case. Be sure to enable the HDPI flag in compiler options

Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 9:53 am
by Stefan
I scale it down.
HDPI flag is ON
The resolution of the original image is HIGH.

Re: resizeimage() make very blurry images

Posted: Mon Oct 21, 2024 11:12 am
by Fred
Ok, I will take a closer look !