HamzaFassi
Programmer
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..
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..