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


C# BitmapSource.Clone方法代码示例

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


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

示例1: ExecuteFilter

        public override BitmapSource ExecuteFilter(BitmapSource inputImage)
        {
            locked = true;
            BitmapSource blurred = inputImage.Clone();

            int pixelCount = inputImage.PixelWidth * inputImage.PixelHeight;
            int[] b = new int[pixelCount];
            int[] g = new int[pixelCount];
            int[] r = new int[pixelCount];

            int[] b2 = new int[pixelCount];
            int[] g2 = new int[pixelCount];
            int[] r2 = new int[pixelCount];

            int width = inputImage.PixelWidth;
            int height = inputImage.PixelHeight;

            byte[] srcPixels = new byte[width * height * 4];
            byte[] destPixels = new byte[width * height * 4];
            inputImage.CopyPixels(srcPixels, width * 4, 0);
            blurred.CopyPixels(destPixels, width * 4, 0);

            for (int i = 0, j = 0; i < pixelCount * 4; i += 4, j++)
            {
                b[j] = srcPixels[i];
                g[j] = srcPixels[i + 1];
                r[j] = srcPixels[i + 2];
            }

            int index = 0;

            int bsum;
            int gsum;
            int rsum;
            int sum;
            int read;
            int start = 0;
            index = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    bsum = gsum = rsum = sum = 0;
                    read = index - _radius;

                    for (int z = 0; z < _kernel.Length; z++)
                    {
                        if (read >= start && read < start + width)
                        {
                            bsum += _multable[z, b[read]];
                            gsum += _multable[z, g[read]];
                            rsum += _multable[z, r[read]];
                            sum += _kernel[z];
                        }
                        ++read;
                    }

                    b2[index] = (bsum / sum);
                    g2[index] = (gsum / sum);
                    r2[index] = (rsum / sum);

                    ++index;
                }
                start += width;
            }

            int tempy;
            int pixelIndex = 0;
            for (int i = 0; i < height; i++)
            {
                int y = i - _radius;
                start = y * width;
                for (int j = 0; j < width; j++)
                {
                    bsum = gsum = rsum = sum = 0;
                    read = start + j;
                    tempy = y;
                    for (int z = 0; z < _kernel.Length; z++)
                    {
                        if (tempy >= 0 && tempy < height)
                        {
                            bsum += _multable[z, b2[read]];
                            gsum += _multable[z, g2[read]];
                            rsum += _multable[z, r2[read]];
                            sum += _kernel[z];
                        }
                        read += width;
                        ++tempy;
                    }

                    destPixels[pixelIndex] = (byte)(bsum / sum);
                    destPixels[pixelIndex + 1] = (byte)(gsum / sum);
                    destPixels[pixelIndex + 2] = (byte)(rsum / sum);

                    pixelIndex += 4;
                }
            }

            blurred = BitmapSource.Create(blurred.PixelWidth, blurred.PixelHeight, 96, 96,
//.........这里部分代码省略.........
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:101,代码来源:GaussianBlurFilter.cs

示例2: MetaOrientation

    private static BitmapSource MetaOrientation(BitmapMetadata meta, BitmapSource ret)
    {
      double angle = 0;
      if ((meta != null) && (ret != null)) //si on a des meta, tentative de récupération de l'orientation
      {
        if (meta.GetQuery("/app1/ifd/{ushort=274}") != null)
        {
          orientation =
            (ExifOrientations)
            Enum.Parse(typeof (ExifOrientations), meta.GetQuery("/app1/ifd/{ushort=274}").ToString());
        }

        switch (orientation)
        {
          case ExifOrientations.Rotate90:
            angle = -90;
            break;
          case ExifOrientations.Rotate180:
            angle = 180;
            break;
          case ExifOrientations.Rotate270:
            angle = 90;
            break;
        }

        if (angle != 0) //on doit effectuer une rotation de l'image
        {
          ret = new TransformedBitmap(ret.Clone(), new RotateTransform(angle));
          ret.Freeze();
        }
      }
      return ret;
    }
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:33,代码来源:Picture.cs

示例3: GetByteData

 /// <summary>
 /// creates a byte array from a bitmapImage
 /// </summary>
 /// <param name="source">the image for creating the byte array</param>
 /// <returns>a byte array</returns>
 public static byte[] GetByteData(BitmapSource source)
 {
     try
     {
         using (MemoryStream ms = new MemoryStream())
         {
             PngBitmapEncoder encoder = new PngBitmapEncoder();
             BitmapFrame frame = BitmapFrame.Create(source.Clone());
             encoder.Frames.Add(frame);
             encoder.Save(ms);
             ms.Seek(0, SeekOrigin.Begin);
             return ms.GetBuffer();
         }
     }
     catch
     {
         return null;
     }
 }
开发者ID:karleule,项目名称:OwlFramework,代码行数:24,代码来源:ImageHelper.cs

示例4: MetaOrientation

 private static BitmapSource MetaOrientation(BitmapMetadata meta, BitmapSource ret)
 {
     double angle = 0.0;
       if (meta != null && ret != null)
       {
     if (meta.GetQuery("/app1/ifd/{ushort=274}") != null)
       Picture.orientation = (Picture.ExifOrientations)Enum.Parse(typeof(Picture.ExifOrientations), meta.GetQuery("/app1/ifd/{ushort=274}").ToString());
     switch (Picture.orientation)
     {
       case Picture.ExifOrientations.Rotate180:
     angle = 180.0;
     break;
       case Picture.ExifOrientations.Rotate270:
     angle = 90.0;
     break;
       case Picture.ExifOrientations.Rotate90:
     angle = -90.0;
     break;
     }
     if (angle != 0.0)
     {
       ret = (BitmapSource)new TransformedBitmap(ret.Clone(), (Transform)new RotateTransform(angle));
       ret.Freeze();
     }
       }
       return ret;
 }
开发者ID:GuzziMP,项目名称:my-films,代码行数:27,代码来源:Picture.cs

示例5: Apply

 public BitmapSource Apply(BitmapSource image)
 {
     return (BitmapSource) image.Clone();
 }
开发者ID:SuperJMN,项目名称:Glass,代码行数:4,代码来源:NoProcessBitmapFilter.cs


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