afwasborstel
10-25-2006, 03:57 AM
I'm playing around with directX to get a screenshot...sofar so good...Now I only want it with an alpha channel...so I can preview it over a canvas...don't ask why...just want it :p
With the following code I get the screenshot...
Public Function ScreenShot() As Bitmap
Try
Dim surf As Direct3D.Surface = device.CreateOffscreenPlainSurface(720, 576, Direct3D.Format.A8R8G8B8, Direct3D.Pool.SystemMemory)
surf = device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
Dim stream As DirectX.GraphicsStream = Direct3D.SurfaceLoader.SaveToStream(Direct3D.ImageFileFormat.Dib, surf)
'Creates the bitmap from the GraphicsStream data.
Dim bmp As System.Drawing.Bitmap = System.Drawing.Bitmap.FromStream(stream)
Return bmp.Clone()
bmp.Dispose()
surf.Dispose()
Catch e As Exception
MessageBox.Show(e.ToString())
End Try
End Function
It seems that with a dib the alpha is embedded...as I read on
http://www.geocities.com/foetsch/d3d8screenshot/d3d8screenshot.htm
and strip the 8 (unused) alpha bits from every pixel
How can we achieve this in VB? Or is there a simpler way to get a bitmap with alpha from a DirectX Render?
ps....when I choose a BMP in surfaceloader..there is no alpha present...when I use TGA and save it as a file there is an alpha channel present...so it seems there should be an alpha channel...
With the following code I get the screenshot...
Public Function ScreenShot() As Bitmap
Try
Dim surf As Direct3D.Surface = device.CreateOffscreenPlainSurface(720, 576, Direct3D.Format.A8R8G8B8, Direct3D.Pool.SystemMemory)
surf = device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
Dim stream As DirectX.GraphicsStream = Direct3D.SurfaceLoader.SaveToStream(Direct3D.ImageFileFormat.Dib, surf)
'Creates the bitmap from the GraphicsStream data.
Dim bmp As System.Drawing.Bitmap = System.Drawing.Bitmap.FromStream(stream)
Return bmp.Clone()
bmp.Dispose()
surf.Dispose()
Catch e As Exception
MessageBox.Show(e.ToString())
End Try
End Function
It seems that with a dib the alpha is embedded...as I read on
http://www.geocities.com/foetsch/d3d8screenshot/d3d8screenshot.htm
and strip the 8 (unused) alpha bits from every pixel
How can we achieve this in VB? Or is there a simpler way to get a bitmap with alpha from a DirectX Render?
ps....when I choose a BMP in surfaceloader..there is no alpha present...when I use TGA and save it as a file there is an alpha channel present...so it seems there should be an alpha channel...