resizeimage() make very blurry images

Just starting out? Need help? Post your questions and find answers here.
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

resizeimage() make very blurry images

Post 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?
Dirk Geppert
Posts: 332
Joined: Fri Sep 22, 2017 7:02 am

Re: resizeimage() make very blurry images

Post by Dirk Geppert »

Just a thought: have you activated dpi aware?
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: resizeimage() make very blurry images

Post by Stefan »

Yes
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: resizeimage() make very blurry images

Post by Fred »

Can you post a code ?
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: resizeimage() make very blurry images

Post 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

Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: resizeimage() make very blurry images

Post 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
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: resizeimage() make very blurry images

Post by Stefan »

I scale it down.
HDPI flag is ON
The resolution of the original image is HIGH.
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: resizeimage() make very blurry images

Post by Fred »

Ok, I will take a closer look !
Post Reply