Page 1 of 1
Display JPG Picture
Posted: Mon Jan 20, 2003 11:48 am
by BackupUser
Restored from previous forum. Originally posted by geoff.
Maybe this one belongs in the beginners section because it's fairly obvious.
I wanted to load a large JPG image and display it on the screen.
We have the command LoadImage() but not LoadJPGImage().
However, if you have DirectX the following works:
Code: Select all
;load and display a JPG file
InitSprite()
OpenWindowedScreen(WindowID(1),0,0,1,1,0,0,0);1 pixel screen
LoadJPEGSprite(1,"c:\pic.jpg",#PB_Sprite_Memory)
SaveSprite(1,"c:\pic.bmp")
FreeSprite(1)
CloseScreen()
StartDrawing(WindowOutput())
LoadImage(1,"c:\pic.bmp")
DrawImage(UseImage(1),0,0)
StopDrawing()
This works OK for large images and is quite fast.
You seem to be able to do this repeatedly without problems.
Anyone see any problem with this, or know a better way?
Posted: Mon Jan 20, 2003 11:55 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> Anyone see any problem with this
Well, it won't work with NT as it doesn't have DirectX, and it may
fail on some systems where DirectX has become damaged in some way.
Otherwise, it's a good contribution for most versions of Windows.
For NT (and all versions of Windows, actually) there's a post by
Danilo that uses a free-and-small DLL called NViewLib. The big
advantage of NViewLib is that you can save images in JPEG format
with it, and also load TGAs, PCXs, and other formats. See here:
viewtopic.php?t=3769
Posted: Tue Jan 21, 2003 12:21 pm
by BackupUser
Restored from previous forum. Originally posted by geoff.
Thanks PB.
I've downloaded the NViewLib and the PB topic.
I'd previously used the Intel IJL11 routines which are very fast but are difficult to use and apparently no longer available. The replacement Intel stuff is far from free.
Posted: Tue Jan 21, 2003 5:53 pm
by BackupUser
Restored from previous forum. Originally posted by TronDoc.
the intel 15 package can be found here:
http://perso.wanadoo.fr/xblite/intel_jpg_lib.zip
elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE

Posted: Tue Apr 29, 2003 5:18 am
by MeMyselfAndI
you could use this code too:
Code: Select all
InitSprite()
UseJPEGImageDecoder()
OpenWindow(1,0,0,640,480,#PB_Window_SystemMenu,"Display JPEG Image")
OpenWindowedScreen( WindowID(),0,0,2272,1712,1,0,0)
ResultLoadSprite = LoadSprite(1, "Hpim0212.jpg" , #PB_Sprite_Memory)
DisplaySprite(1, 0, 0)
Repeat
Event = WaitWindowEvent()
FlipBuffers()
Delay(20)
Until Event = #PB_Event_CloseWindow
The only BAD thing is, that you have to know the dimensions of the JPEG image before you actually can display an image in full.
Maybe Fred could change this... (loadimage before openscreen...)
Posted: Tue Apr 29, 2003 9:04 am
by Fred
Just use LoadImage() before openscreen and use LoadSprite() after.. not really a problem. Sprites could never be loaded before Openscreen() because we don't know the pixel format at this moment.
Posted: Tue Apr 29, 2003 3:59 pm
by MeMyselfAndI
Thanks Fred this works fine:
Code: Select all
InitSprite()
UseJPEGImageDecoder()
OpenWindow(1,0,0,0,0,#PB_Window_SystemMenu,"Display JPEG Image")
LoadImage(1,"adams600.jpg")
ResizeWindow(ImageWidth(), ImageHeight())
OpenWindowedScreen( WindowID(),0,0,ImageWidth() ,ImageHeight() ,1,0,0)
FreeImage(1)
ResultLoadSprite = LoadSprite(1, "adams600.jpg" , #PB_Sprite_Memory)
DisplaySprite(1, 0, 0)
Repeat
Event = WaitWindowEvent()
FlipBuffers()
Delay(2)
Until Event = #PB_Event_CloseWindow
One thing though:
If I display a JPEG file with IrfanView it's much sharper than displaying the same JPEG file with PureBasic. Is there a way to get it better

Posted: Tue Apr 29, 2003 11:32 pm
by geoff
My original posting here is obsolete.
I made this suggestion before it was possible to use LoadImage()
for a JPG image.