• <tfoot id='14tOK'></tfoot>
    • <bdo id='14tOK'></bdo><ul id='14tOK'></ul>
    1. <small id='14tOK'></small><noframes id='14tOK'>

      <legend id='14tOK'><style id='14tOK'><dir id='14tOK'><q id='14tOK'></q></dir></style></legend>

        <i id='14tOK'><tr id='14tOK'><dt id='14tOK'><q id='14tOK'><span id='14tOK'><b id='14tOK'><form id='14tOK'><ins id='14tOK'></ins><ul id='14tOK'></ul><sub id='14tOK'></sub></form><legend id='14tOK'></legend><bdo id='14tOK'><pre id='14tOK'><center id='14tOK'></center></pre></bdo></b><th id='14tOK'></th></span></q></dt></tr></i><div id='14tOK'><tfoot id='14tOK'></tfoot><dl id='14tOK'><fieldset id='14tOK'></fieldset></dl></div>
      1. 如何在 Windows 10 UWP 中复制和调整图像大小

        How to Copy and Resize Image in Windows 10 UWP(如何在 Windows 10 UWP 中复制和调整图像大小)

        <small id='G7nTE'></small><noframes id='G7nTE'>

      2. <legend id='G7nTE'><style id='G7nTE'><dir id='G7nTE'><q id='G7nTE'></q></dir></style></legend>
            1. <tfoot id='G7nTE'></tfoot>
                  <bdo id='G7nTE'></bdo><ul id='G7nTE'></ul>
                  <i id='G7nTE'><tr id='G7nTE'><dt id='G7nTE'><q id='G7nTE'><span id='G7nTE'><b id='G7nTE'><form id='G7nTE'><ins id='G7nTE'></ins><ul id='G7nTE'></ul><sub id='G7nTE'></sub></form><legend id='G7nTE'></legend><bdo id='G7nTE'><pre id='G7nTE'><center id='G7nTE'></center></pre></bdo></b><th id='G7nTE'></th></span></q></dt></tr></i><div id='G7nTE'><tfoot id='G7nTE'></tfoot><dl id='G7nTE'><fieldset id='G7nTE'></fieldset></dl></div>

                    <tbody id='G7nTE'></tbody>
                  本文介绍了如何在 Windows 10 UWP 中复制和调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用了

                  解决方案

                  我可能想要返回原始 BitmapImage 的副本,而不是修改原始文件.

                  没有直接复制一个BitmapImage的好方法,但是我们可以多次重复StorageFile.

                  如果您只想选择一张图片,显示它,同时显示原始图片的调整大小的图片,您可以将 StorageFile 作为参数传递,如下所示:

                  public static async TaskResizedImage(StorageFile ImageFile, int maxWidth, int maxHeight){IRandomAccessStream 输入流 = 等待 ImageFile.OpenReadAsync();BitmapImage sourceImage = new BitmapImage();sourceImage.SetSource(输入流);var origHeight = sourceImage.PixelHeight;var origWidth = sourceImage.PixelWidth;var ratioX = maxWidth/(float)origWidth;var ratioY = maxHeight/(float)origHeight;var ratio = Math.Min(ratioX, ratioY);var newHeight = (int)(origHeight * ratio);var newWidth = (int)(origWidth * ratio);sourceImage.DecodePixelWidth = newWidth;sourceImage.DecodePixelHeight = newHeight;返回源图像;}

                  在这种情况下,您只需要调用此任务并显示调整大小的图像,如下所示:

                  smallImage.Source = await ResizedImage(file, 250, 250);

                  如果你想保留 BitmapImage 参数由于某些原因(比如 sourceImage 可能是修改过的位图但不是直接从文件中加载的),并且你想重新调整这个新图片的大小另一个,您需要先将调整大小的图片另存为文件,然后打开此文件并重新调整大小.

                  I have used the code from http://www.codeproject.com/Tips/552141/Csharp-Image-resize-convert-and-save to resize images programmatically. However, that project uses the System.Drawing libraries, which are not available to Windows 10 applications.

                  I have tried using the BitmapImage class from Windows.UI.Xaml.Media.Imaging instead, but it does not seem to offer the functionality that was found in System.Drawing..

                  Has anyone had any luck being able to resize (scale down) images in Windows 10? My application will be processing images from multiple sources, in different formats/sizes, and I am trying to resize the actual images to save space, rather than just letting the application size it to fit the Image in which it is being displayed.

                  EDIT

                  I have modified the code from the above mentioned link, and have a hack which works for my specific need. Here it is:

                  public static BitmapImage ResizedImage(BitmapImage sourceImage, int maxWidth, int maxHeight)
                  {
                      var origHeight = sourceImage.PixelHeight;
                      var origWidth = sourceImage.PixelWidth;
                      var ratioX = maxWidth/(float) origWidth;
                      var ratioY = maxHeight/(float) origHeight;
                      var ratio = Math.Min(ratioX, ratioY);
                      var newHeight = (int) (origHeight * ratio);
                      var newWidth = (int) (origWidth * ratio);
                  
                      sourceImage.DecodePixelWidth = newWidth;
                      sourceImage.DecodePixelHeight = newHeight;
                  
                      return sourceImage;
                  }
                  

                  This way seems to work, but ideally rather than modifying the original BitmapImage, I would like to create a new/copy of it to modify and return instead.

                  Here is a shot of it in action:

                  解决方案

                  I may want to return a copy of the original BitmapImage rather than modifying the original.

                  There is no good method to directly copy a BitmapImage, but we can reuse StorageFile for several times.

                  If you just want to select a picture, show it and in the meanwhile show the re-sized picture of original one, you can pass the StorageFile as parameter like this:

                  public static async Task<BitmapImage> ResizedImage(StorageFile ImageFile, int maxWidth, int maxHeight)
                  {
                      IRandomAccessStream inputstream = await ImageFile.OpenReadAsync();
                      BitmapImage sourceImage = new BitmapImage();
                      sourceImage.SetSource(inputstream);
                      var origHeight = sourceImage.PixelHeight;
                      var origWidth = sourceImage.PixelWidth;
                      var ratioX = maxWidth / (float)origWidth;
                      var ratioY = maxHeight / (float)origHeight;
                      var ratio = Math.Min(ratioX, ratioY);
                      var newHeight = (int)(origHeight * ratio);
                      var newWidth = (int)(origWidth * ratio);
                  
                      sourceImage.DecodePixelWidth = newWidth;
                      sourceImage.DecodePixelHeight = newHeight;
                  
                      return sourceImage;
                  }
                  

                  In this scenario you just need to call this task and show the re-sized image like this:

                  smallImage.Source = await ResizedImage(file, 250, 250);
                  

                  If you want to keep the BitmapImage parameter due to some reasons (like the sourceImage might be a modified bitmap but not directly loaded from file), and you want to re-size this new picture to another one, you will need to save the re-sized picture as a file at first, then open this file and re-size it again.

                  这篇关于如何在 Windows 10 UWP 中复制和调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                  <i id='AsGUF'><tr id='AsGUF'><dt id='AsGUF'><q id='AsGUF'><span id='AsGUF'><b id='AsGUF'><form id='AsGUF'><ins id='AsGUF'></ins><ul id='AsGUF'></ul><sub id='AsGUF'></sub></form><legend id='AsGUF'></legend><bdo id='AsGUF'><pre id='AsGUF'><center id='AsGUF'></center></pre></bdo></b><th id='AsGUF'></th></span></q></dt></tr></i><div id='AsGUF'><tfoot id='AsGUF'></tfoot><dl id='AsGUF'><fieldset id='AsGUF'></fieldset></dl></div>

                  <small id='AsGUF'></small><noframes id='AsGUF'>

                      <bdo id='AsGUF'></bdo><ul id='AsGUF'></ul>

                    • <legend id='AsGUF'><style id='AsGUF'><dir id='AsGUF'><q id='AsGUF'></q></dir></style></legend>
                        <tfoot id='AsGUF'></tfoot>
                          <tbody id='AsGUF'></tbody>