Resize and resave images

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Resize and resave images

Post 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
r-i-v-e-r
User
User
Posts: 20
Joined: Thu May 09, 2024 5:18 pm

Re: Resize and resave images

Post 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).
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Resize and resave images

Post by jak64 »

Hello r-i-v-e-r

Indeed, I was not using the png encoder.

It's OK, thank you
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Resize and resave images

Post by boddhi »

Under Windows, you can use GetLastError_() API with error code descriptions here.
Normally, only few error codes should occur : 3, 5, 8, ?
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Resize and resave images

Post 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,
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Resize and resave images

Post 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
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Resize and resave images

Post by boddhi »

Aparte

I just saw you are from Ciboure. Je vais assez souvent à Socoa :wink:
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Resize and resave images

Post by jak64 »

Thank you boddhi.
Yes Socoa is a very pretty place, I live 600 meters from the beach and the Socoa fort.
Post Reply