【问题标题】:resizing the image in wp7在 wp7 中调整图像大小
【发布时间】:2011-04-22 19:35:45
【问题描述】:

最近我开始创建一个社交网络 WP7 应用程序。在发送用户数据的网络请求时,他们在回调时提供用户图像的 url。我的问题是在绑定此图像时,我得到了不同尺寸的图像。即很难保持图像大小均匀。因此,用户界面看起来很普通。我需要做些什么才能使这个图像大小均匀。编写转换器或其他解决方案。任何人都可以帮我解决这个问题。我尝试给出宽度、高度和填充属性,但仍然得到相同的结果。

【问题讨论】:

    标签: windows-phone-7


    【解决方案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();
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2010-11-20
      • 1970-01-01
      • 2015-01-09
      • 2013-01-16
      • 2011-01-09
      相关资源
      最近更新 更多