QB64 Phoenix Edition
How does QB64 support saving 8bit images? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: How does QB64 support saving 8bit images? (/showthread.php?tid=3640)



How does QB64 support saving 8bit images? - CMR - 04-27-2025

I've tried loading a 32 bit image and saving it as an 8bit image, but it doesn't seem to work.  Image editors like Graphics Gale can't seem to open it, and when I try to reload it that fails also.

Code: (Select All)

''Test loading a 32bit image and saving it to 8 bit
Option _Explicit

Screen _NewImage(320,240,256)

Dim img32& : img32& = _LoadImage("img32.png", 256)
Dim img8bit& : img8bit& = _NewImage(64, 64, 256)
_PutImage (0,0),img32&, img8bit&

_SaveImage "img8bit.bmp", img8bit&
_FreeImage(img32&)
_FreeImage(img8bit&)

Sleep
End

checking the image:
Code: (Select All)

''Load and check an image
Dim img8& : img8& = _LoadImage("img8bit&.bmp", 256)

Screen _NewImage(320, 240, 256)

_PutImage (0,0), img8&

_FreeImage(img8&)
sleep
end



RE: How does QB64 support saving 8bit images? - ahenry3068 - 04-27-2025

For one thing your file name in the 2nd code block is incorrect.

I don't particularly like the Dithering that QB64PE produces for 8 bit images anyway.   I would have probably done this with a **SHELL** command to ImageMagick.


RE: How does QB64 support saving 8bit images? - ahenry3068 - 04-27-2025

Code: (Select All)
Option _Explicit

Screen _NewImage(320, 240, 256)

Dim img32&: img32& = _LoadImage("img32.png")
Dim img8bit&: img8bit& = _NewImage(640, 617, 256)
_PutImage (0, 0), img32&, img8bit&

_SaveImage "img8bit.bmp", img8bit&
_FreeImage (img32&)
_FreeImage (img8bit&)

Sleep
End

This worked for me..  
[Image: img32.png]


RE: How does QB64 support saving 8bit images? - Petr - 04-27-2025

I would just like to point out that the built-in QB64PE dithering provides better results if you load a 32-bit image with the LoadImage command with parameter 257 instead of parameter 256. Then the visual appearance is very similar to the original.


RE: How does QB64 support saving 8bit images? - CMR - 04-27-2025

(04-27-2025, 02:59 AM)ahenry3068 Wrote: For one thing your file name in the 2nd code block is incorrect.

I don't particularly like the Dithering that QB64PE produces for 8 bit images anyway.   I would have probably done this with a **SHELL** command to ImageMagick.


You know, that might actually be a thing.   Big Grin  I need to stop posting at night. It's all auto complete's fault.