Page 1 of 1

Resize and resave images

Posted: Thu May 16, 2024 8:29 pm
by jak64
Good morning,
I want to write a program that allows me to resize images and resave them.

I wrote this little piece of program to test but it doesn't work!

I would also like to know how to recover the wording of the error generated by Purebasic

Thank you for your help

Code: Select all

EnableExplicit
UseJPEGImageDecoder()
UsePNGImageDecoder()

Enumeration
  #Image1
EndEnumeration

Global file$ = "c:\images\toto.jpg"

If LoadImage(#Image1, file$)
      ResizeImage(#Image1, 380, 285)
      If Not SaveImage(#Image1, file$ + ".png", #PB_ImagePlugin_PNG)
        Debug "erreur" + " --> "
      EndIf
EndIf

Re: Resize and resave images

Posted: Thu May 16, 2024 8:36 pm
by r-i-v-e-r
jak64 wrote: Thu May 16, 2024 8:29 pm

Code: Select all

      If Not SaveImage(#Image1, file$ + ".png", #PB_ImagePlugin_PNG)
You've attempted to save with the PNG encoder (#PB_ImagePlugin_PNG), however you've only used the decoder:
jak64 wrote: Thu May 16, 2024 8:29 pm

Code: Select all

UseJPEGImageDecoder()
UsePNGImageDecoder()
If you add a UsePNGImageEncoder() call, it should function just fine.

jak64 wrote: Thu May 16, 2024 8:29 pm I would also like to know how to recover the wording of the error generated by Purebasic
AFAIK, discerning a detailed error code/message is not possible in most cases. I believe there was a feature request somewhere on the forum asking for a new function similar to the Win32 GetLastError(), which would definitely be useful here (although an immense task to integrate for the entire PB command set).

Re: Resize and resave images

Posted: Thu May 16, 2024 8:50 pm
by jak64
Hello r-i-v-e-r

Indeed, I was not using the png encoder.

It's OK, thank you

Re: Resize and resave images

Posted: Thu May 16, 2024 9:33 pm
by boddhi
Under Windows, you can use GetLastError_() API with error code descriptions here.
Normally, only few error codes should occur : 3, 5, 8, ?

Re: Resize and resave images

Posted: Thu May 16, 2024 9:42 pm
by jak64
Hello boddhi

Thank you for your answer. I went to look but I didn't understand anything, is there an example with Purebasic?

Sincerely,

Re: Resize and resave images

Posted: Thu May 16, 2024 9:47 pm
by boddhi
You read my reply too fast... I was writing one. :mrgreen:

Code: Select all

String.s=""
CreateImage(0,20,20)
If Not SaveImage(0,"C:\zzz\Example.bmp") ; Be sure than "C:\zzz\" path doesn't exist!
  Select GetLastError_()
   Case 3:String="Path not found"
   Case 5:String="Access denied"
   Case 8:String="Not enough memory to complete the operation"
   Case 39:String="Disk full"
   Case 53:String="Network path not found"
   Default:String="Unknown error"
 EndSelect
 MessageRequester("Save operation",String)
EndIf
Non-exhaustive list

Re: Resize and resave images

Posted: Thu May 16, 2024 9:58 pm
by boddhi
Aparte

I just saw you are from Ciboure. Je vais assez souvent à Socoa :wink:

Re: Resize and resave images

Posted: Thu May 16, 2024 11:40 pm
by jak64
Thank you boddhi.
Yes Socoa is a very pretty place, I live 600 meters from the beach and the Socoa fort.