调整图像大小并保留纵横比

时间:2011-08-03 18:58:37

标签: c# silverlight windows-phone-7

我正在使用Windows Phone 7上的PhotoChooserTask加载图像。加载照片后,我希望能够立即调整照片大小,同时保持其宽高比,这样就不会在UI中显示图像,然后保存到了IsolatedStorage。

到目前为止,我有这样的事情:

    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);
            }
        }
    }

它正在调整图像大小,但我无法弄清楚如何保持图像的宽高比。

1 个答案:

答案 0 :(得分:2)

您可以查询图像属性的高度和宽度,并确定纵横比。如果您知道高度或宽度,则可以计算其他值。您需要在代码中添加查询这些属性,然后进行一些数学运算。

相关问题