Convert DIB to bitmap with alpha

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 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

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()
Catch e As Exception
End Try

End Function

It seems that with a dib the alpha is I read on

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 it seems there should be an alpha channel...

11-21-2006, 02:34 PM
I may be missing the point here because I'm tired but do you know that .bmp files cannot hold Alpha information nor can .jpg, I'm not to sure about .png but Gif can. Please tell me if I've lost it here.

11-21-2006, 02:44 PM
Bitmaps in Net have alphachannels.....

11-21-2006, 02:50 PM
Yup missed it, lol. I never knew that though. Could you read my post(below yours) if you know your stuff about graphics? I might be able to use that in mine lol.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum