Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert RenderTargetBitmap to Drawing.bitmap have black background

Status
Not open for further replies.

HamzaFassi

Programmer
Apr 12, 2010
1
CA
hi everyone, my firsttime here
I hope I will find some help..

I m capturing the visual of a WPF page using system.windoes.media.targetRenderer then I have to convert it to a system.drawing.Image.. the thing is.. it generates a black image. it appears that it have something to do with the alpha parameter that is not available in the system.drawing.. I dont know how to deal with it. I cannot use the jpg workaround since I use an API to convert this bitmap to pdf (only accepts system.drawing). I can convert the API though.. but I prefere to leave it as an edge alternative..

here are some snapshots:

//capture the bitmap from the visual tree

System.Windows.Media.Imaging.RenderTargetBitmap renderTarget =
new RenderTargetBitmap( ( int )page.Size.Width,
( int )page.Size.Height,
96, // WPF (Avalon) units are 96dpi based
96,
System.Windows.Media.PixelFormats.Default );

renderTarget.Render( page.Visual );


BitmapEncoder encoder = new BmpBitmapEncoder();

BitmapFrame bitMapFrame = BitmapFrame.Create( renderTarget );

encoder.Frames.Add( bitMapFrame );

//when I save it here, the picture is completely balck, except if theres some colors on it, I mean, instead of a white background, I have a black one, so all the black elements are invisible..

using( Stream stm = File.Create( @"C:\ImageFile2.bmp" ) )
{
encoder.Save( stm );
}

any suggestions?

similar to thread732-691849 which have not been solved..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top