当前位置: 首页>>代码示例>>C#>>正文


C# WriteableBitmap.CopyTo方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.CopyTo方法的具体用法?C# WriteableBitmap.CopyTo怎么用?C# WriteableBitmap.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadBitmap

   static public Texture2D LoadBitmap(string imageName, int w, int h)
   {
      //
      // Load a bitmap image through writeablebitmap so that we can populate our device
      // texture
      //

      StreamResourceInfo sr = Application.GetResourceStream(new Uri(imageName, UriKind.Relative));
      BitmapImage bs = new BitmapImage();
      bs.SetSource(sr.Stream);

      var wb = new WriteableBitmap(w, h);

      ScaleTransform t = new ScaleTransform();
      t.ScaleX = (double)w / (double)bs.PixelWidth;
      t.ScaleY = (double)h / (double)bs.PixelHeight;

      Image image = new Image();
      image.Source = bs;
      wb.Render(image, t);
      wb.Invalidate();

      Texture2D tex = new Texture2D(GraphicsDeviceManager.Current.GraphicsDevice, wb.PixelWidth, wb.PixelHeight, false, SurfaceFormat.Color);
      wb.CopyTo(tex);

      return tex;
   }
开发者ID:amoldeshpande,项目名称:slartoolkit,代码行数:27,代码来源:ContentManager.cs

示例2: LoadBitmapAndMip

   private static Texture2D LoadBitmapAndMip(Stream stream)
   {
      var bs = new BitmapImage();
      bs.SetSource(stream);

      // Get dimensions        
      int w = bs.PixelWidth;
      int h = bs.PixelHeight;

      if ((w % 2 != 0 && w != 1) || (h % 2 != 0 && h != 1))
         throw new InvalidOperationException("Bitmap must be power of 2.");

      // Calculate mip levels
      int mipLevels = 1;
      int maxDimension = Math.Max(w, h);
      while (maxDimension > 1)
      {
         mipLevels++;
         maxDimension /= 2;
      }

      // Create the chain
      Texture2D tex = new Texture2D(GraphicsDeviceManager.Current.GraphicsDevice, w, h, true, SurfaceFormat.Color);

      // Put bitmap into a renderable image
      Image image = new Image();
      image.Source = bs;

      // Generate mip level data
      for (int level = 0; level < mipLevels; level++)
      {
         var wb = new WriteableBitmap(w, h);

         // Scale to current mip level
         ScaleTransform t = new ScaleTransform();
         t.ScaleX = (double)w / (double)bs.PixelWidth;
         t.ScaleY = (double)h / (double)bs.PixelHeight;

         // Black out the image
         for (int c = 0; c < w * h; c++)
            wb.Pixels[c] = 0;

         // Small mip levels are rendering as white, so don't render
         if (w > 1 && h > 1)
            wb.Render(image, t);

         // Update WB
         wb.Invalidate();

         // Grab pixel data
         wb.CopyTo(tex, level, null, 0, 0);

         // Shrink for the next level
         if (w != 1)
            w /= 2;
         if (h != 1)
            h /= 2;
      }

      return tex;
   }
开发者ID:amoldeshpande,项目名称:slartoolkit,代码行数:61,代码来源:ContentManager.cs


注:本文中的System.Windows.Media.Imaging.WriteableBitmap.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。