Reputation: 1785
Recently i started creating a social network WP7 application. In that while sending web request for user data they are giving a url for user image while callback. My issue is while binding this image i am getting images in different sizes. ie Its hard to keep the image size uniform. Because of this the user interface looks pretty ordinary. What i need to do for make this image size uniform. Writing a converter or other solution. Can any one please help me to resolve this issue. I tried giving width, height and fill property but still getting the same result.
Upvotes: 1
Views: 1210
Reputation: 1445
You can try this:
WriteableBitmap resizedImage = new WriteableBitmap(imageToResize);//imageToResize is BitmapImage
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (System.IO.IsolatedStorage.IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
{
double maxHeight = newWidth;
double maxWidth = newHeight;
double scaleX = 1;
double scaleY = 1;
if (pixHt > maxHeight)
scaleY = maxHeight / pixHt;
if (pixWt > maxWidth)
scaleX = maxWidth / pixWt;
double scale = Math.Min(scaleY, scaleX);
int newWidth1 = Convert.ToInt32(pixWt * scale);
int newHeight1 = Convert.ToInt32(pixHt * scale);
resizedImage.SaveJpeg(isfs, newWidth1, newHeight1, 0, 70);
isfs.Close();
}
}
Upvotes: 1