Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Canvas save to image ( image not as big as canvas )

$
0
0

Hey everyone,

I'm using canvas named "Can" in my program and I needed to save it as .png or .jpg, so I went here and found this code:

 RenderTargetBitmap rtb = new RenderTargetBitmap(
(int)Can.ActualWidth, 
(int)Can.ActualHeight, 
96, 
96, 
PixelFormats.Pbgra32);
rtb.Render(Can);

PngBitmapEncoder enc = new PngBitmapEncoder();

                enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(rtb));

using (var stm = System.IO.File.Create(@"D:\image.png"))
 {
    enc.Save(stm);
 }

And I get the .png, but it's not the whole picture! Half an inch at the bottom is cut off. I make a rectangle on the edge of the canvas, and I cannot see the bottom line of the rectangle. Am I using the height/width of the canvas wrong?

And one more question, what is the difference between canvas.Width and canvas.ActualWidth in this case?

Thank you!


Knowledge: C, C++, C#, Java, Pawn


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>