User Tools

Site Tools


displaying_20a_20jpeg_20or_20gif_20in_20a_20picture_20box

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

displaying_20a_20jpeg_20or_20gif_20in_20a_20picture_20box [2018/03/31 13:19]
127.0.0.1 external edit
displaying_20a_20jpeg_20or_20gif_20in_20a_20picture_20box [2018/04/15 17:24] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Displaying a JPEG or GIF in a picture box===== =====Displaying a JPEG or GIF in a picture box=====
  
-//by Richard Russell, November 2006//\\ \\  The main BBC BASIC for Windows documentation explains how to display a BMP image in a picture box (i.e. a //static control// having the SS_BITMAP style). The code it lists is as follows:\\ \\ +//by Richard Russell, November 2006//\\ \\  The main BBC BASIC for Windows documentation explains how to display a BMP image in a picture box (i.e. a //static control// having the SS_BITMAP style). The code it lists is as follows: 
 + 
 +<code bb4w> ​
         LR_LOADFROMFILE = 16         LR_LOADFROMFILE = 16
         STM_SETIMAGE = &172         STM_SETIMAGE = &172
         SYS "​LoadImage",​ 0, bmpfile$, 0, cx%, cy%, LR_LOADFROMFILE TO hbitmap%         SYS "​LoadImage",​ 0, bmpfile$, 0, cx%, cy%, LR_LOADFROMFILE TO hbitmap%
         SYS "​SendDlgItemMessage",​ !dlg%, id%, STM_SETIMAGE,​ 0, hbitmap%         SYS "​SendDlgItemMessage",​ !dlg%, id%, STM_SETIMAGE,​ 0, hbitmap%
-for a static control in a dialogue box, or:\\ \\ +</​code>​ 
 + 
 +for a static control in a dialogue box, or: 
 + 
 +<code bb4w>
         LR_LOADFROMFILE = 16         LR_LOADFROMFILE = 16
         STM_SETIMAGE = &172         STM_SETIMAGE = &172
         SYS "​LoadImage",​ 0, bmpfile$, 0, cx%, cy%, LR_LOADFROMFILE TO hbitmap%         SYS "​LoadImage",​ 0, bmpfile$, 0, cx%, cy%, LR_LOADFROMFILE TO hbitmap%
         SYS "​SendMessage",​ hbox%, STM_SETIMAGE,​ 0, hbitmap%         SYS "​SendMessage",​ hbox%, STM_SETIMAGE,​ 0, hbitmap%
-for a static box on the main window.\\ \\  This technique does not work for JPEG or GIF images, because **LoadImage** can't load files of those types. The solution is to use the following function (or the one described [[/​Loading%20a%20GIF%20or%20JPEG%20image|here]],​ which gives more control of the image size) instead of LoadImage:\\ \\ +</​code>​ 
 + 
 +for a static box on the main window.\\ \\  This technique does not work for JPEG or GIF images, because **LoadImage** can't load files of those types. The solution is to use the following function (or the one described [[/​Loading%20a%20GIF%20or%20JPEG%20image|here]],​ which gives more control of the image size) instead of LoadImage: 
 + 
 +<code bb4w>
         DEF FNloadimage(file$,​ cx%, cy%)         DEF FNloadimage(file$,​ cx%, cy%)
         LOCAL iid{}, hbm%, hcopy%, pic%, ole%, olpp%, text%         LOCAL iid{}, hbm%, hcopy%, pic%, ole%, olpp%, text%
Line 38: Line 48:
  
         = hcopy%         = hcopy%
-Using this function you can display a JPEG, GIF, BMP, ICO, EMF or WMF image in a picture box as follows:\\ \\ +</​code>​ 
 + 
 +Using this function you can display a JPEG, GIF, BMP, ICO, EMF or WMF image in a picture box as follows: 
 + 
 +<code bb4w>
         STM_SETIMAGE = &172         STM_SETIMAGE = &172
         hbitmap% = FNloadimage(imgfile$,​ cx%, cy%)         hbitmap% = FNloadimage(imgfile$,​ cx%, cy%)
         SYS "​SendDlgItemMessage",​ !dlg%, id%, STM_SETIMAGE,​ 0, hbitmap%         SYS "​SendDlgItemMessage",​ !dlg%, id%, STM_SETIMAGE,​ 0, hbitmap%
-for a static control in a dialogue box, or:\\ \\ +</​code>​ 
 +for a static control in a dialogue box, or: 
 + 
 +<code bb4w>
         STM_SETIMAGE = &172         STM_SETIMAGE = &172
         hbitmap% = FNloadimage(imgfile$,​ cx%, cy%)         hbitmap% = FNloadimage(imgfile$,​ cx%, cy%)
         SYS "​SendMessage",​ hbox%, STM_SETIMAGE,​ 0, hbitmap%         SYS "​SendMessage",​ hbox%, STM_SETIMAGE,​ 0, hbitmap%
-for a static box on the main window.\\ \\  Note that the filename **imgfile$** must include the drive letter, to distinguish it from an internet URL. As always, you must send a message to a dialogue box only //after// the **PROC_showdialog**,​ because until then the dialogue box does not exist.\\ \\  When you have finished with it (e.g. on closing the static control or exiting your program) delete the bitmap handle as follows:\\ \\ +</​code>​ 
 +for a static box on the main window.\\ \\  Note that the filename **imgfile$** must include the drive letter, to distinguish it from an internet URL. As always, you must send a message to a dialogue box only //after// the **PROC_showdialog**,​ because until then the dialogue box does not exist.\\ \\  When you have finished with it (e.g. on closing the static control or exiting your program) delete the bitmap handle as follows: 
 + 
 +<code bb4w>
         SYS "​DeleteObject",​ hbitmap%         SYS "​DeleteObject",​ hbitmap%
 +</​code>​
 +
 When displaying an image in a dialogue box be aware of the issues discussed here: [[/​Supporting%20different%20DPI%20values|Supporting different DPI values]]. When displaying an image in a dialogue box be aware of the issues discussed here: [[/​Supporting%20different%20DPI%20values|Supporting different DPI values]].
displaying_20a_20jpeg_20or_20gif_20in_20a_20picture_20box.txt · Last modified: 2018/04/15 17:24 by richardrussell