Saving Snapshots As JPG using DirectX8

Started by
3 comments, last by Namethatnobodyelsetook 18 years, 11 months ago
I'm using this sub I made to make snapshots as bmp:


Public Sub DirectX_Snapshot(ByVal File_Path As String)

    Dim Surface As Direct3DSurface8
    Dim SrcPalette As PALETTEENTRY
    Dim SrcRect As RECT
    Dim Direct3D_Display_Mode As D3DDISPLAYMODE

    'get display dimensions
    Direct3D_Device.GetDisplayMode Direct3D_Display_Mode

    'create a surface to put front buffer on,
    'GetFrontBuffer always returns D3DFMT_A8R8G8B8
    Set Surface = Direct3D_Device.CreateImageSurface(Direct3D_Display_Mode.Width, Direct3D_Display_Mode.Height, D3DFMT_A8R8G8B8)

    'get data from front buffer
    Direct3D_Device.GetFrontBuffer Surface

    'we are saving entire area of this surface
    
    With SrcRect
    
        .Left = 0
        .Right = Direct3D_Display_Mode.Width
        .Top = 0
        .bottom = Direct3D_Display_Mode.Height
        
    End With

    'save this surface to a BMP file
    Direct3DX.SaveSurfaceToFile File_Path, D3DXIFF_BMP, Surface, SrcPalette, SrcRect

End Sub

But since I decided to save them as jpeg, there's a problem. After switching it from D3DXIFF_BMP to D3DXIFF_JPG, it locks up and doesn't save at all. I think it has a lot to do with the D3DFMT_A8R8G8B8 format. Is there another DirectX format I need to use for jpegs or is there another way around this? Thanks in advance.
Advertisement
I don't know if this is the problem or not, but jpegs don't store alpha information. Try using a png (or gif) for alpha, or D3DFMT_X8R8G8B8 for jpegs.
Thanks. I'll give it a whirl.
Ok now I have a problem. I get an Automation error on this line

Direct3D_Device.GetFrontBuffer Surface

Plus in the comments in my code it says GetFrontBuffer always returns D3DFMT_A8R8G8B8. Any other way?
While the save functions take a nice image format parameter, I seem to remember the DX8 docs say that only BMP (and DDS? I can't remember) are supported. DX9 docs seem to say almost everything is supported.

No idea what's wrong with the GetFrontBuffer... sorry.

This topic is closed to new replies.

Advertisement