Page 1 of 1

SaveSprite(#Sprite, Filename$ , #PB_ImagePlugin_JPEG)

Posted: Tue Apr 29, 2003 5:43 am
by MeMyselfAndI
I have a jpeg file from a digital camera and 24bpp.
After loading and manipulating it , it should be saved as file.
SaveSprite as BMP with #PB_ImagePlugin_BMP works fine, but as JPEG fails...

But 18MB instead of 2MB is way too big!

Posted: Tue Apr 29, 2003 5:53 am
by MeMyselfAndI
Maybe its a good idea to post some test code...

Code: Select all

#OrgSprite = 1
#IntermediateSprite = 2
#NewSprite = 3

InitSprite()
UseJPEGImageDecoder() 
OpenWindow(1,0,0,640,480,#PB_Window_SystemMenu,"ImageConverter")
OpenWindowedScreen( WindowID(),0,0,2726,2282,1,0,0)

; size of Hpim0212.jpg = 2272x1712
ResultLoadSprite = LoadSprite(#OrgSprite, "Hpim0212.jpg" , #PB_Sprite_Memory) 
;Debug ResultLoadSprite
ResultSpriteWidth = SpriteWidth(#OrgSprite) 
;Debug ResultSpriteWidth
ResultSpriteHeight = SpriteHeight(#OrgSprite) 
;Debug ResultSpriteHeight

;Calldebugger

Width = ResultSpriteWidth + (ResultSpriteWidth / 5)
Height = ResultSpriteHeight + (ResultSpriteHeight / 3)
CreateSprite(#IntermediateSprite, Width, Height, #PB_Sprite_Memory) 

DisplaySprite(#IntermediateSprite, 0, 0) 
DisplayRGBFilter(0, 0, 2726, 2282, 255, 255, 255) 
DisplaySprite(#OrgSprite, ResultSpriteWidth / 10, ResultSpriteHeight / 6) 

Repeat
  Event = WaitWindowEvent()
  FlipBuffers()
  Delay(20)
Until Event = #PB_Event_CloseWindow

GrabSprite(#NewSprite, 0, 0,  2726, 2282, #PB_Sprite_Memory) 
;Debug SaveSprite(#NewSprite, "Hpim0212NEW.bmp", #PB_ImagePlugin_BMP) ; this works
Debug SaveSprite(#NewSprite, "Hpim0212NEW.jpg", #PB_ImagePlugin_JPEG)  ; this NOT!!!


CallDebugger
BTW: it would have been nice to do this exersise completely in memory instead of displaying it - but you can't load sprites without opening a screen, and CopySprite always changes the size of the CopyToSprite.
Maybe:
CopySprite(#Sprite1, #Sprite2 [, Mode])
should be changed in:
CopySprite(#Sprite1, x of Sprite2, y of Sprite2, #Sprite2 [, Mode])
without changing the size of Sprite1,so it's possible to copy/overlay a new Sprite over an old one and be able to specify the position.

Posted: Tue Apr 29, 2003 9:00 am
by Fred
Where is the UseJPEGImageEncoder() ? :)

Posted: Tue Apr 29, 2003 4:09 pm
by MeMyselfAndI
Fred wrote:Where is the UseJPEGImageEncoder() ? :)
Ups, my fault. Sorry Fred. :oops:
Found the UseJPEGImageDecoder() but not the UseJPEGImageEncoder().

Now it works fine, thanks.
Feel free to move this topic to the "Dumb User Code" Section. :wink: