frogman_j
asked on
DDraw/VB image conversion
I am using a DirectDraw Type library and I am not sure on how to convert a picture from an image control to a form that I can use to blit to the back buffer. I seriously need help.
Why so many points? 200 is the standard rate for a difficult question. 400 perhaps for something that is excruciatingly hard to crack. But 1200 is just frivolous...
Agree with caraf_g...
Is your problem REALLY so serious (for example, you need release software within nearest 20 minutes? :))
Sincerely yours,
Crin
Is your problem REALLY so serious (for example, you need release software within nearest 20 minutes? :))
Sincerely yours,
Crin
True, but what's more important, you'll probably get optimal help for a 400 pointer... put in a 1200 pointer and you'll be attracting the chancers who are hoping to get away with half-baked answers ;-)
Seems to be just a typo... think this is 12 pts question... 120 - if trouble is really serious :)))
Crin
Crin
<g>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was just frustrated because I don't have the experience with windows or directx, and don't know any where to learn windows(not MFC) programming. Oh, and the ddraw.tlb can be obtained at various places on the internet for you who don't know what I'm talking about.
ASKER
I also have 1531 idle points and wanted to get the answer FAST!
Here is a generic function derived from the code above. It takes a picture object and blt's it to the DirectDrawSurface passed to the function.
' Blt's a picture in a DirectDraw surface
Public Function CopyPicToDDS(dd As IDirectDraw, pic As StdPicture, dds As IDirectDrawSurface) As Long
Dim hbm As Long ' Handle on bitmap
Dim bm As BITMAP ' Bitmap header
Dim ddsd As DDSURFACEDESC ' Surface description
Dim hdcImage As Long ' Handle on image
Dim mhdc As Long ' Handle on surface context
Dim lRet As Long
'Get picture handle
hbm = pic.Handle
' Get bitmap info
GetObject hbm, Len(bm), bm
' Fill surface description
With ddsd
.dwSize = Len(ddsd)
.dwFlags = DDSD_CAPS + DDSD_HEIGHT + DDSD_WIDTH
.DDSCAPS.dwCaps = DDSCAPS_OFFSCREENPLAIN
.ddpfPixelFormat.dwSize = 8
.dwWidth = bm.bmWidth
.dwHeight = bm.bmHeight
End With
' Create memory device
hdcImage = CreateCompatibleDC(ByVal 0&)
' Select the bitmap in this memory device
SelectObject hdcImage, hbm
' Restore the surface
dds.Restore
' Get the surface's DC
dds.GetDC mhdc
' Copy from the memory device to the DirectDrawSurface
lRet = StretchBlt(mhdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, _
bm.bmWidth, bm.bmHeight, SRCCOPY)
' Release the surface's DC
dds.ReleaseDC mhdc
' Release the memory device and the bitmap
DeleteDC hdcImage
CopyPicToDDS = lRet 'return value of StretchBlt
End Function
The function can be called like this:
Call CopyPicToDDS(lpDD, Image1.Picture, lpDDSBack)
Where:
lpDDS is the IDirectDraw object
Image1.Picture is the picture object
lpDDSBack is the (Back) IDirectDrawSurface object
' Blt's a picture in a DirectDraw surface
Public Function CopyPicToDDS(dd As IDirectDraw, pic As StdPicture, dds As IDirectDrawSurface) As Long
Dim hbm As Long ' Handle on bitmap
Dim bm As BITMAP ' Bitmap header
Dim ddsd As DDSURFACEDESC ' Surface description
Dim hdcImage As Long ' Handle on image
Dim mhdc As Long ' Handle on surface context
Dim lRet As Long
'Get picture handle
hbm = pic.Handle
' Get bitmap info
GetObject hbm, Len(bm), bm
' Fill surface description
With ddsd
.dwSize = Len(ddsd)
.dwFlags = DDSD_CAPS + DDSD_HEIGHT + DDSD_WIDTH
.DDSCAPS.dwCaps = DDSCAPS_OFFSCREENPLAIN
.ddpfPixelFormat.dwSize = 8
.dwWidth = bm.bmWidth
.dwHeight = bm.bmHeight
End With
' Create memory device
hdcImage = CreateCompatibleDC(ByVal 0&)
' Select the bitmap in this memory device
SelectObject hdcImage, hbm
' Restore the surface
dds.Restore
' Get the surface's DC
dds.GetDC mhdc
' Copy from the memory device to the DirectDrawSurface
lRet = StretchBlt(mhdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, _
bm.bmWidth, bm.bmHeight, SRCCOPY)
' Release the surface's DC
dds.ReleaseDC mhdc
' Release the memory device and the bitmap
DeleteDC hdcImage
CopyPicToDDS = lRet 'return value of StretchBlt
End Function
The function can be called like this:
Call CopyPicToDDS(lpDD, Image1.Picture, lpDDSBack)
Where:
lpDDS is the IDirectDraw object
Image1.Picture is the picture object
lpDDSBack is the (Back) IDirectDrawSurface object
Actually, you can omit the first parameter (dd) as it is not used in this function.
BTW: this code references the DirectX5.tlb available at
http:\\www.chez.com\scribe
BTW: this code references the DirectX5.tlb available at
http:\\www.chez.com\scribe
ASKER
Erick37
Danke schön! I'm actually using a different typelib but the method you used should work anyway. I am actually doing this for a really lame ass VB class at school and I just wanted to make an awesome game, but I needed some info on DirectX. Thanks again. I like the first example better.
frogman_j
Danke schön! I'm actually using a different typelib but the method you used should work anyway. I am actually doing this for a really lame ass VB class at school and I just wanted to make an awesome game, but I needed some info on DirectX. Thanks again. I like the first example better.
frogman_j
ASKER
You Left out 2 things though:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Thanks!
Glad it helped.
I did not notice the missing declares at first, probably because I referenced the Win32.tlb; so the compiler did not complain. When I ran the sample on my Win95 computer, it did catch the omissions.
Good luck on the game.
Glad it helped.
I did not notice the missing declares at first, probably because I referenced the Win32.tlb; so the compiler did not complain. When I ran the sample on my Win95 computer, it did catch the omissions.
Good luck on the game.
Do you mean standard Image control?
If so, Me.Picture = Me.Image1.Picture works fine...
Please specify problem more detailed.
Sincerely yours,
Crin
PS. Sorry, english is not my native...