2011-04-22 108 views
1

最近我開始創建一個社交網絡WP7應用程序。在發送用戶數據的Web請求時,他們在回調時爲用戶圖像提供一個url。我的問題是綁定這張圖片時,我得到了不同大小的圖片。即它很難保持圖像大小一致。正因爲如此,用戶界面看起來很普通。我需要做的是使圖像大小一致。寫一個轉換器或其他解決方案。任何人都可以幫助我解決這個問題。我試着給寬度,高度和填充屬性,但仍然得到相同的結果。在wp7中調整圖片的尺寸

回答

1


你可以試試這個:


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