This image is from scanner. I am using C# WPF to show image.But my problem is that image showing is not unclear. Below is my code( .xaml and .cs) .I found 2 ways to tranfer the file into image source. But both not work well. If you use any image view sofeware to open image, the image is very clear.
.xaml
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="WindowLoaded">
<Grid>
<Image Name="image"></Image>
</Grid>
</Window>
.cs(just part of code)
private void WindowLoaded(object sender, RoutedEventArgs e)
{
string StrImage = @"ImageFilePath";
this.image.Source = FileToImageSource(StrImage);
//this.image.Source = FileToImageSource_2(StrImage);
}
//blurry
public static BitmapImage FileToImageSource(string strFileName)
{
byte[] bytes = File.ReadAllBytes(strFileName);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = new MemoryStream(bytes);
bitmap.EndInit();
return bitmap;
}
//blurry too
public static BitmapImage FileToImageSource_2(string strFileName)
{
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri(strFileName);
logo.EndInit();
return logo;
}
Update:
i have try but failed
image property : RenderOptions.BitmapScalingMode="NearestNeighbor"
Stretch="None"
blurry image vs clear image
image file