Save image as JPG?

Blitz3D Forums/Blitz3D Programming/Save image as JPG?

John Blackledge(Posted 2006) [#1]
Does anyone have any code which can save an internal B3D image handle out as a jpg, as opposed to the SaveImage(bmp) method?

Before anyone suggests the archives, I've already tried, and PngExporter images fail to save, and FreeImage crashes with a Memory Allocation Error.

It's so frustrating to load in a jpg, resize it, SaveImage() out, and then find the filesize for the reduced image is bigger than the original - coz it's now a bmp!


kevin8084(Posted 2006) [#2]
SaveImage command can be used to save a .jpg file as well as a .bmp. If you run the small include program you'll see that the saved file is, indeed, a .jpg file. Hope that this helps.
******************************************
Graphics3D 800,600

SetBuffer BackBuffer()

image=CreateImage(40,40)
SetBuffer ImageBuffer(image)
ClsColor 255,0,0
Cls
SetBuffer BackBuffer()
While Not KeyHit(1)
If MouseHit(1) Then
SaveImage(image,"testing.jpg")
End If
UpdateWorld()
RenderWorld()
Flip
Wend
End

Regards, Kevin


John Blackledge(Posted 2006) [#3]
Yes, but it is still internally a bitmap (no compression) even though the extension is jpg.

Also Paint Shop Pro won't load it, although Blitz does.


kevin8084(Posted 2006) [#4]
You're right...just checked internal structure and it IS a bitmap...are there any jpeg libraries that you could use with your program?


big10p(Posted 2006) [#5]
Don't know what problem you're having with FreeImage, but I use it without probs. Take a look at this thread:
http://www.blitzbasic.com/Community/posts.php?topic=57729
Note that the code I posted there has the JPG stuff commented out - because I didn't need it - but it should work fine if you remove them.


John Blackledge(Posted 2006) [#6]
Well, I put the decls in the userlibs folder, dll in place, used the guy's save routine, and got a Memory Allocation Error on one of his lines of code. It's obviously accessing the dll but screwing up on one of his memory jobbies.

Just to show willing I've tried to download it all again from BlitzCoder - now it's 'File Not Found'. Hey-ho. On and on <sigh>.

Any other options? - I don't trust code that works for some people, but not for others, in it's simplest implementation.


John Blackledge(Posted 2006) [#7]
It doesn't have to be jpg by the way, it can be png, as long as it's compressed.


big10p(Posted 2006) [#8]
You put both the decls in, named as specified, right?


John Blackledge(Posted 2006) [#9]
As stated previously - did as instructed.
_His_ code-line failed on a memory command, so the dll was running, but... your guess is as good as mine.


John Blackledge(Posted 2006) [#10]
Right.
I've used dll v3.8.
I've used dll v3.9.1.

I've used every damn include and example I could find, and they were either Blitz Plus or if B3D produced the infamous MAE.

Does _anyone_ have a copy of FreeImage.dll with decls and test code that works with B3D that they could email to me? - Coz so far, I think this a windup!


John Blackledge(Posted 2006) [#11]
I finally got sent a coordinated decls/dll for FreeImage which works! Thanks to IPete2.

What should be noted is:
a) you can't use a Blitz image handle to save via FreeImage - the resultant jpg is non-standard.
b) if you read in an image via FreeImage then the image handle produced is unusable by Blitz.
c) the only probable use is, as I am doing, writing out a Blitz image (SaveImage() as bmp) then reading it in via FreeImage and saving it out as a jpg to ensure compression/reduction.

Still, if anyone wants this email me.