I have a PNG with transparency that loses a lot of quality when I convert it to ImageSource. What I do to convert it is the following:
public static ImageSource ToImageSource()
{ Bitmap bitmap = Properties.Resources.Image;
IntPtr hBitmap = bitmap.GetHbitmap();
ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
RenderOptions.SetBitmapScalingMode(wpfBitmap, BitmapScalingMode.HighQuality);
return wpfBitmap;
}
But the quality is really bad. when I call directly to the file on my computer the quality is correct:
<DataGridTemplateColumn Width="14" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="C:\Users\MyUser\Desktop\Image.png" Width="14" Height="14"></Image>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Is there another way to transform the resource without losing quality and transparency?