0

I have come across a need for image resizing in my Windows 8 app(C# xaml). Searching the topic has given me quite a lot of results. But most of them are using the WritableBitmapEx codeplex class or by separate class. Isn't there a single function which handles resizing gracefully? I have a Listview and its template contains an Image element and it is data bound. Every item's image element uri is set to images from folders. The list view is rendered in 2 sizes(760,200) and (380,100) based on settings.. The images are by default saved in 760,200 size..

So now what happens is when the listview is in 380,100 size it still shows the large image and hence gets cut off.. I want to scale down the image and fit it into the image element size..

Its there any function offered by the platform which allows us to do this? Does the Windows.Graphics.Imaging have any methods?(I din find one :( )

Denis
  • 4,115
  • 1
  • 18
  • 20
alfah
  • 2,077
  • 1
  • 31
  • 55

2 Answers2

2

The easiest solution is to set your images' Stretch property to "UniformToFill" and use a single image (the larger one). Since your aspect ratios are the same this will have the effect of simply scaling the image. Note: this assumes the images are just different sizes of the same source material.

Another relatively simple option would be to use converters to point to the appropriate path. Use one converter per view size, and modify the path string to point to the correct folder for the size you want.

If I was writing this, I'd go with the first option, though.

ZombieSheep
  • 29,603
  • 12
  • 67
  • 114
  • I tried the following code and the the image is blurred and large. Somehow its not working – alfah Apr 17 '13 at 11:34
  • So are you saying that your template uses bindings for size rather than using the known dimension of the images (760x200)? I don't get what you are saying - your question implies your dimensions are fixed. Also, make sure you are using the path of your larger image so that it only ever scales down in size – ZombieSheep Apr 17 '13 at 16:48
  • the sizes can be 760x200 or 380x100.. and it is selected based on settings.. it works with Stretch with Uniform.. So i think it should be fine.. Thank you! – alfah Apr 18 '13 at 09:06
1

Here's solution without use of WritableBitmapEx

How to resize Image in C# WinRT/winmd?

Community
  • 1
  • 1
Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115