I would like some help with my images. I just want to save my screen and gladly I could. But some softwares can't properly see them. For example:
If I put my image (.jpg) in facebook, or open it with Paint, it will be like this:
but if I open the same image (the exactly same image) with the default Windows Program or some, it will appear like this:
So, I was doing this "printscreen" in my WPF application, here is my code:
private void btSalvar_Click_1(object sender, RoutedEventArgs e)
{
BitmapSource bmp = VisualToBitmap.Render(gridSalvar);
Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
dialog.Filter = "Imagem JPG(*.jpg)|*.jpg";
if (dialog.ShowDialog() == true)
{
System.Windows.Media.Imaging.PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
System.IO.FileStream fs = new System.IO.FileStream(dialog.FileName, System.IO.FileMode.Create);
encoder.Save(fs);
fs.Close();
}
And the class created to do so:
class VisualToBitmap
{
public static System.Windows.Media.Imaging.BitmapSource Render(System.Windows.Media.Visual Visual, int Resolution = 96)
{
System.Windows.Media.Imaging.RenderTargetBitmap render;
double width, height;
int pixelWidth, pixelHeight;
width = (double)Visual.GetValue(System.Windows.FrameworkElement.ActualWidthProperty);
height = (double)Visual.GetValue(System.Windows.FrameworkElement.ActualHeightProperty);
pixelWidth = Convert.ToInt32((width / 96) * Resolution);
pixelHeight = Convert.ToInt32((height / 96) * Resolution);
render = new System.Windows.Media.Imaging.RenderTargetBitmap(
pixelWidth, pixelHeight, Resolution, Resolution,
System.Windows.Media.PixelFormats.Pbgra32);
render.Render(Visual);
return render;
}
}
can someone please help me fix this? Thanks guys!