hi
i want to load jpg and gif files into a picturebox at run time. but i don't know how or i have forgot. can u please help
thanks
Printable View
hi
i want to load jpg and gif files into a picturebox at run time. but i don't know how or i have forgot. can u please help
thanks
VB Code:
Picture1.Picture = LoadPicture("myPic.jpg") 'open pic. Picture1.Picture = LoadPicture() 'Clear the picturebox.
Or you can load it into a DC with this and then BitBlt the image into the picturebox
VB Code:
Option Explicit Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDc As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hDc As Long) As Long Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hDc As Long, ByVal hObject As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Public Function GenerateDC(FileName As String) As Long Dim DC As Long, picTemp As IPictureDisp DC = CreateCompatibleDC(0) If DC < 1 Then Exit Function End If Set picTemp = LoadPicture(FileName) SelectObject DC, picTemp DeleteObject picTemp Set picTemp = Nothing GenerateDC = DC End Function Private Sub Form_Load() Dim myDc As Long myDc = GenerateDC("c:\jamie\jamie.bmp") With Picture1 .AutoRedraw = True BitBlt .hDc, 0, 0, .Width, .Height, myDc, 0, 0, vbSrcCopy End With End Sub
...showoff...:p
oh yeah :D ;)Quote:
Originally posted by Eyes.Only
...showoff...:p
quick question tho...what does that do for you? your still using LoadPicture inside your generateDC function so i fail to see the benefit..
explain to me smartypants! explain!;)
Because you've now loaded the image into an offscreen device context, which means that you can now paint it (very fast) by using BitBlt into any pictureboxes you want.
Thats how you do 2d graphics in games. You load the images into a DC, then BitBlt them later onto the screen.
If you goto my website and scroll to the very right, you'll see how I load all the images for the ships and what not into DCs for use later.
oh yea? well ...well...my dad could beat up your dad!
haha
actually thats a cool thing to know, i havent done much with DCs in vb...i almost forgot about them. heh
Yup handy little buggers. If you look in the Picutre Resizing/Changing thread (or something along those lines) you'll see lots more code for device contexts, and also code for using the StretchBlt and SetStretchBltMode functions
i always wanted to load a pic into dc without LoadPicture because its so slow when dealing with a lot of pictures.
i also remember wanting to create gif files without the lzw compression, but i ended up having to create the images through a dll i made in vc++ and then use api to access it through my vb...
they just need better gfx handling functions in vb.