|
-
Jun 6th, 2002, 01:48 AM
#1
Bitmaps, APIs, PictureBoxes = Frustrating
Hey all. I've been beating this thing over and over, and I still don't know what's occuring.
I'm trying to get my function to load up an entire bitmap image within the space of the picturebox (ie: a thumbnail.) So far, I've been able to get the image into the box, but I can't figure a way around the color appearance. When I load a 24-bit bmp, it still displays it like a 8-bit! How do I fix this?
Here's the code I'm using (at the moment):
VB Code:
Public Function DisplayBMP(picBox As PictureBox, fileName As String) As Boolean
Dim hDC As Long, hBMP As Long
Dim fileNo As Integer, counter As Integer
Dim imgSize As POINT
DisplayBMP = False
fileNo = FreeFile
Open fileName For Binary As fileNo
Get #fileNo, 19, imgSize
Close fileNo
counter = 0
Do
hDC = CreateCompatibleDC(picBox.hDC)
counter = counter + 1
Loop While hDC < 1 Or counter < 15
If hDC < 1 Then
MsgBox "Failed on Device Context creation"
Exit Function
End If
hBMP = LoadImage(0, fileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_DEFAULTSIZE)
If hBMP = 0 Then
DeleteDC hDC
MsgBox "Failed to load the image"
Exit Function
End If
SelectObject hDC, hBMP
DeleteObject hBMP
StretchBlt picBox.hDC, 0, 0, picBox.Width, picBox.Height, hDC, 0, 0, imgSize.X * 15, imgSize.Y * 15, vbSrcCopy
picBox.Refresh
DeleteDC hDC
End Sub
Any help on how to fix my color problem, or on how to better implement this, is greatly appreciated.
Destined
-
Jun 7th, 2002, 10:15 AM
#2
Retired VBF Adm1nistrator
Why don't you just load the image straight into an IPictureDisp and then use StretchBlt straight from there ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 7th, 2002, 10:22 AM
#3
Frenzied Member
If you want a simplier way, you can use an Image control, it has a property that automatically stretches the image to its own size.
As to your code, everything seems to be fine with it, I have no idea why it shows up in 256 colors.
-
Jun 7th, 2002, 10:24 AM
#4
Retired VBF Adm1nistrator
We are of course assuming you're using a resolution of greater than 256 colours in windows
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 7th, 2002, 10:43 AM
#5
Addicted Member
You need to use SetStretchBltMode and pass it COLORONCOLOR, I believe - otherwise it looks 256-color. You could also just use LoadImage, that function can do resizing at load.
"1 4m 4 1337 #4xz0r!'
Janus
-
Jun 7th, 2002, 10:45 AM
#6
Retired VBF Adm1nistrator
As I said, he should just get the image into an IPictureDisp and Blit from there.
Use a generateDC() function.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 7th, 2002, 11:01 AM
#7
Addicted Member
LoadImage uses bi-linear filtering
"1 4m 4 1337 #4xz0r!'
Janus
-
Jun 7th, 2002, 11:06 AM
#8
Retired VBF Adm1nistrator
Whatever 
If you use a GenerateDC() function though you end up with a reusable device context, and its very easy to use once you have a working GenerateDC()
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 7th, 2002, 11:20 AM
#9
Thanx everyone for the help. 
plenderj
I think I just want to use pure API calls to get it working. For what it's worth, that was how I originally did it, but the colors didn't seem to come out right. And, yes, I am running in more than 256 colors. 
Janus
Excellent, this worked great. I just added the following code:
VB Code:
...
DeleteObject hBMP
SetStretchBltMode picBox.hDC, COLORONCOLOR ' This works!
StretchBlt picBox.hDC, 0, 0, picBox.Width, picBox.Height, hDC, 0, 0, imgSize.x * 15, imgSize.y * 15, vbSrcCopy
picBox.Refresh
...
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
|