Convert DIB to bitmap with alpha

afwasborstel
10-25-2006, 04: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...

Paystey
11-21-2006, 03: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.

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

Paystey
11-21-2006, 03: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