Display JPG Picture

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Display JPG Picture

Post 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?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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 :wink:
MeMyselfAndI
User
User
Posts: 10
Joined: Fri Apr 25, 2003 8:23 pm

Post 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...)
.
. Greetings
.
. from all three of us...
.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
MeMyselfAndI
User
User
Posts: 10
Joined: Fri Apr 25, 2003 8:23 pm

Post 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 :?:
.
. Greetings
.
. from all three of us...
.
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

My original posting here is obsolete.

I made this suggestion before it was possible to use LoadImage()
for a JPG image.
Post Reply