BBC BASIC for Windows
Programming >> BBC BASIC language >> Jpg display in bbcbasic4 windows http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1399911509 Jpg display in bbcbasic4 windows
Post by larry on May 12th, 2014, 4:18pm
below is the code I'm using in BBC4win to place a jpg in a window. The Procedure uses an api call. I want it to display in whatever size the image is. rather than me having to specify the size. any help would be greatly appreciated
cls
rem maximize window SW_MAXIMIZE = 3 sys "ShowWindow", @hwnd%, SW_MAXIMIZE
rem Set parematers for loading the jpg onto the window picture$="i:\jbg\jbg1\00000jb.jpg" xpos%=0 ypos%=0 xsize%=450 ysize%=600
rem call the procedure that shows the picture to the window procdisplay(picture$,xpos%,ypos%,xsize%,ysize%)
repeat rem Wait for keypress Key%=get rem Translate key press to action code case Key% of when 27 cls:end otherwise Code%=0 endcase until Code%<>0
rem this is the procedure that opens and displays the picture
def procdisplay(picture$,xpos%,ypos%,xsize%,ysize%) local oleaut32%, olpp%, iid%, gpp%, hmw%, hmh%, picture%, res% sys "LoadLibrary", "OLEAUT32.DLL" to oleaut32% sys "GetProcAddress", oleaut32%, "OleLoadPicturePath" to olpp% if olpp%=0 error 100, "Could not get address of OleLoadPicturePath" dim iid% local 15, picture% local 513 sys "MultiByteToWideChar", 0, 0, picture$, -1, picture%, 256 iid%!0 = &7BF80980 iid%!4 = &101ABF32 iid%!8 = &AA00BB8B iid%!12 = &AB0C3000 sys olpp%, picture%, 0, 0, 0, iid%, ^gpp% if gpp% = 0 error 100, "OleLoadPicturePath failed" sys !(!gpp%+24), gpp%, ^hmw% : rem. IPicture::get_Width sys !(!gpp%+28), gpp%, ^hmh% : rem. IPicture::get_Height sys !(!gpp%+32), gpp%, @memhdc%, xpos%, ypos%, xsize%, ysize%, 0, \ \ hmh%, hmw%, -hmh%, 0 to res% if res% error 100, "IPicture::Render failed" sys !(!gpp%+8), gpp% : rem. IPicture::Release sys "InvalidateRect", @hwnd%, 0, 0 sys "UpdateWindow", @hwnd% endproc
Re: Jpg display in bbcbasic4 windows
Post by rtr on May 12th, 2014, 5:58pm
I want it to display in whatever size the image is. rather than me having to specify the size.
The easiest way would probably be to take the image dimensions (hmw% and hmh%), convert them from HIMETRIC units to pixels (assume 96 DPI), and then put those values into the xsize% and ysize% variables respectively: