PDA

Click to See Complete Forum and Search --> : DirectDrawSurface to BMP file???


Feb 23rd, 2000, 09:34 AM
Hi, I found this function to save a DirectDrawSurface7 to a .bmp file but it's seem to have a problem.

Sometime I got this error "object variable or with block not set" and sometime this one "invalid use of property" on this line. The OLE automation references are specified. And I really don't understand why?

TempPicture.Height = SurfDesc.lHeight

----------------------------------------------
Option Explicit

Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

Public Sub SaveSurface(File As String, Surf As DirectDrawSurface7)
Dim TempPicture As IPictureDisp
Dim SurfDesc As DDSURFACEDESC2
Dim EmptyRect As RECT
Dim X As Long
Dim Y As Long

'Get the surface's Description
Surf.GetSurfaceDesc SurfDesc

'Now apply that to the internal picture
TempPicture.Height = SurfDesc.lHeight
TempPicture.Width = SurfDesc.lWidth

'You must lock the surface memmory
Surf.Lock EmptyRect, SurfDesc, DDLOCK_WAIT

For X = 0 To SurfDesc.lWidth
For Y = 0 To SurfDesc.lHeight
'Now copy the pixels to the internal picture structure
SetPixel TempPicture.Handle, X, Y, Surf.GetLockedPixel(X, Y)
Next
Next

'Release the surface
Surf.Unlock EmptyRect

'Save the internal picture structure to file
SavePicture TempPicture, File
End Sub

------------------------------------------------------