Resize Image and retaining aspect ratio
I am loading an image using the the PhotoChooserTask on Windows Phone 7. After loading the photo, I want to be able to immediately resize the photo whilst keeping it aspect ratio and this is without displaying the image in th开发者_运维问答e UI, then save the to the IsolatedStorage.
So far, I have something like this:
private void SaveToIsolatedStorage(Stream imageStream, string fileName)
{
using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fileStream = myIsolatedStorage.CreateFile(fileName))
{
var wbBarcodeImage = new WriteableBitmap(100, 100);
wbBarcodeImage.SetSource(imageStream);
wbBarcodeImage.Resize(100, 100, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
wbBarcodeImage.SaveJpeg(fileStream, 100, 100, 0, 85);
}
}
}
It's resizing the image, but I am unable to figure out how to keep the aspect ratio of the image.
You can query the image properties for height and width and determine aspect ration. If you then know either height or width, you can calculate the other value. Your need to add querying these properties to your code and then a little math.
精彩评论