how can i resize an image .png or jpg ?

Just starting out? Need help? Post your questions and find answers here.
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

how can i resize an image .png or jpg ?

Post by skinkairewalker »

hi , i have problems with command ResizeImage , if i call this comand , image lost ...
someone have a simple code with a png image to i test ?
falsam
Posts: 286
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: how can i resize an image .png or jpg ?

Post by falsam »

Try this code.

Code: Select all

Procedure Loaded(Type, Filename$, ObjectId)
  
  ; Display the image in a new window
  OpenWindow(#PB_Any, 0, 0, 0, 0, "Image resize", #PB_Window_Background)
  ImageGadget(#PB_Any, 10, 10, ImageWidth(ObjectId), ImageHeight(ObjectId), ImageID(ObjectId))
  
  ResizeImage(ObjectId, 280, 80)
  
  ImageGadget(#PB_Any, 400, 10, 250, 80, ImageID(ObjectId))
  
EndProcedure

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

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

; Load Image
LoadImage(#PB_Any, "demo.png")
Image test : Image

➽ Windows 11 - jdk-11.0.2 - SB 3.00 - Android 15
https://falsam.com

Sorry for my poor english
falsam
Posts: 286
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: how can i resize an image .png or jpg ?

Post by falsam »

Another method if you have several images.

Code: Select all

Declare Prologue()
Declare Loaded(Type, Filename$, ObjectId)
Declare LoadingError(Type, Filename$, ObjectId)
Declare Start()

Prologue()

Procedure Prologue()
  ; Load Image
  LoadImage(0, "background.jpg")
  LoadImage(1, "demo.png")
  
  ; Register the loading event before calling any resource load command
  BindEvent(#PB_Event_Loading, @Loaded())
  BindEvent(#PB_Event_LoadingError, @LoadingError())  
EndProcedure

Procedure Loaded(Type, Filename$, ObjectId)
  Static CountElement  
  CountElement + 1 
  
  ;background Resize
  If IsImage(0)
    ResizeImage(0, DesktopWidth(0), DesktopHeight(0))
  EndIf
  
  If CountElement = 2
    Start()
  EndIf
EndProcedure

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

Procedure Start()
  OpenWindow(0, 0, 0, 0, 0, "Image resize", #PB_Window_Background)
  ImageGadget(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), ImageID(0))
  ImageGadget(#PB_Any, 10, 10, ImageWidth(1), WindowHeight(1), ImageID(1))  
EndProcedure
Assets :
-backgroung.jpg
Image

-demo.png
Image

➽ Windows 11 - jdk-11.0.2 - SB 3.00 - Android 15
https://falsam.com

Sorry for my poor english
skinkairewalker
Posts: 120
Joined: Tue Jun 14, 2016 7:17 pm

Re: how can i resize an image .png or jpg ?

Post by skinkairewalker »

Thanks You very Much :D
Post Reply