|
-
Dec 21st, 2001, 03:21 AM
#1
Thread Starter
Addicted Member
how load jpg into picbox @ runtime
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
-
Dec 21st, 2001, 03:26 AM
#2
Hyperactive Member
VB Code:
Picture1.Picture = LoadPicture("myPic.jpg") 'open pic.
Picture1.Picture = LoadPicture() 'Clear the picturebox.
-
Dec 21st, 2001, 03:38 AM
#3
Retired VBF Adm1nistrator
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
-
Dec 21st, 2001, 04:03 AM
#4
Hyperactive Member
...showoff...
-
Dec 21st, 2001, 04:04 AM
#5
Retired VBF Adm1nistrator
-
Dec 21st, 2001, 04:11 AM
#6
Hyperactive Member
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!
-
Dec 21st, 2001, 04:15 AM
#7
Retired VBF Adm1nistrator
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.
-
Dec 21st, 2001, 04:20 AM
#8
Hyperactive Member
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
-
Dec 21st, 2001, 04:25 AM
#9
Retired VBF Adm1nistrator
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
-
Dec 21st, 2001, 04:32 AM
#10
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|