2

How to Resize the image in windows phone 8.0 application using C# without loss of quality and to display full image

What I did,

My XAML Code:

<StackPanel Orientation="Vertical">
    <TextBlock Text="Select Image" FontSize="45" Height="106"></TextBlock>
    <Image Name="ImgPrev" Height="455" Stretch="None" ></Image>
</StackPanel>

My C# code

public MainPage()
{

    InitializeComponent();

    // Sample code to localize the ApplicationBar
    //BuildLocalizedApplicationBar();

    BitmapImage image = new BitmapImage();
    image.SetSource(Application.GetResourceStream(new Uri(@"Assets/Bug.jpg", UriKind.Relative)).Stream);
    image.DecodePixelType = DecodePixelType.Logical;
    image.CreateOptions = BitmapCreateOptions.BackgroundCreation;
    image.CreateOptions = BitmapCreateOptions.DelayCreation;
    Image img = new Image();
    img.Source = image;
    WriteableBitmap wb = new WriteableBitmap(image);
    wb.Resize(1000, 1000, WriteableBitmapExtensions.Interpolation.Bilinear);
    using(MemoryStream stream=new MemoryStream())
    {
        wb.SaveJpeg(stream, 1000, 1000, 0, 100);
        BitmapImage resize = new BitmapImage();
        resize.SetSource(stream);
        ImgPrev.Source = resize;
    }

}

The original image Actual size of the image is 38 MB, Dimention 10240x6400 , height:10240, width:6400

What result I am getting is below image

enter image description here

Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
user1934329
  • 529
  • 1
  • 6
  • 18

0 Answers0