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


C# BitmapSource.CopyPixels方法代码示例

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


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

示例1: ExecuteFilter

        public override BitmapSource ExecuteFilter(BitmapSource inputImage)
        {
            byte[] sourceBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4];
            byte[] destBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4];

            inputImage.CopyPixels(sourceBytes, inputImage.PixelWidth * 4, 0);

            float redAdjust = 1.0f + (this.Warmth / 100.0f);
            float blueAdjust = 1.0f - (this.Warmth / 100.0f);

            GaussianBlurFilter blur = new GaussianBlurFilter(3 * Softness);
            BrightnessContrastFilter bc = new BrightnessContrastFilter(Lighting, -Lighting / 2);
            DesaturateFilter desat = new DesaturateFilter();

            inputImage = blur.ExecuteFilter(inputImage);
            inputImage.CopyPixels(destBytes, inputImage.PixelWidth * 4, 0);

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

            for (int i = 0; i < sourceBytes.Length; i += 4)
            {
                byte b = sourceBytes[i];
                byte g = sourceBytes[i + 1];
                byte r = sourceBytes[i + 2];
                byte a = sourceBytes[i + 3];

                bc.PerformOperation(ref b, ref g, ref r, ref a);
                desat.PerformOperation(ref b, ref g, ref r, ref a);

                double rD = r * redAdjust;
                double bD = r * blueAdjust;

                if (rD > 255) rD = 255;
                else if (rD < 0) rD = 0;

                if (bD > 255) bD = 255;
                else if (bD < 0) bD = 0;

                destBytes[i] = PixelBlend.BlendOverlay(b, destBytes[i]);
                destBytes[i + 1] = PixelBlend.BlendOverlay(g, destBytes[i + 1]);
                destBytes[i + 2] = PixelBlend.BlendOverlay(r, destBytes[i + 2]);
                destBytes[i + 3] = PixelBlend.BlendOverlay(a, destBytes[i + 3]);
            }

            return BitmapSource.Create(inputImage.PixelWidth, inputImage.PixelHeight, 96, 96,
                inputImage.Format, null, destBytes, inputImage.PixelWidth * 4);
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:48,代码来源:PortraitEffect.cs

示例2: ChangeColor

 /// <summary>
 /// 更改颜色。
 /// </summary>
 /// <param name="pic">原图</param>
 /// <param name="srcBGRA">要更改的像素,顺序为蓝绿红透明通道</param>
 /// <param name="dstBGRA">要更改为的像素,顺序为蓝绿红透明通道</param>
 /// <param name="isIgnoreAlpha">是否忽略Alpha通道的对照值</param>
 /// <returns>更改后的图片</returns>
 public BitmapSource ChangeColor(BitmapSource pic, byte[] srcBGRA, byte[] dstBGRA, bool isIgnoreAlpha)
 {
     int PixelWidth = pic.PixelWidth;
     int PixelHeight = pic.PixelHeight;
     byte[] picArray = new byte[PixelWidth * PixelHeight * 4];
     pic.CopyPixels(picArray, PixelWidth * 4, 0);
     if (picArray[0] == srcBGRA[0]) { picArray[0] = dstBGRA[0]; }
     if (picArray[1] == srcBGRA[1]) { picArray[1] = dstBGRA[1]; }
     if (picArray[2] == srcBGRA[2]) { picArray[2] = dstBGRA[2]; }
     if (picArray[3] == srcBGRA[3]) { picArray[3] = dstBGRA[3]; }
     for (int i = 4; i < picArray.Count(); i++)
     {
         if (i % 4 == 0)
         {
             if (picArray[i] == srcBGRA[0]) { picArray[i] = dstBGRA[0]; }
         }
         if (i % 4 == 1)
         {
             if (picArray[i] == srcBGRA[1]) { picArray[i] = dstBGRA[1]; }
         }
         if (i % 4 == 2)
         {
             if (picArray[i] == srcBGRA[2]) { picArray[i] = dstBGRA[2]; }
         }
         if (i % 4 == 3)
         {
             if (isIgnoreAlpha) { picArray[i] = dstBGRA[3]; }
             else { if (picArray[i] == srcBGRA[3]) { picArray[i] = dstBGRA[3]; } }
         }
     }
     BitmapSource bpic = BitmapSource.Create(PixelWidth, PixelHeight, 96, 96, System.Windows.Media.PixelFormats.Bgr32, null, picArray, PixelWidth * 4);
     return bpic;
 }
开发者ID:IceLitty,项目名称:Minecraft-Command-Helper,代码行数:41,代码来源:ImageFix.cs

示例3: CopyBitmapSource

        public static BitmapSource CopyBitmapSource(BitmapSource source)
        {
            // Calculate stride of source
            int stride = source.PixelWidth * (source.Format.BitsPerPixel / 8);

            // Create data array to hold source pixel data
            byte[] data = new byte[stride * source.PixelHeight];

            // Copy source image pixels to the data array
            source.CopyPixels(data, stride, 0);

            // Create WriteableBitmap to copy the pixel data to.
            WriteableBitmap target = new WriteableBitmap(
              source.PixelWidth,
              source.PixelHeight,
              source.DpiX, source.DpiY,
              source.Format, null);

            // Write the pixel data to the WriteableBitmap.
            target.WritePixels(
              new Int32Rect(0, 0, source.PixelWidth, source.PixelHeight),
              data, stride, 0);

            return target;
        }
开发者ID:Dig-Doug,项目名称:BU_KinectShowcase,代码行数:25,代码来源:ImageExtensions.cs

示例4: ExecuteFilter

        public override BitmapSource ExecuteFilter(BitmapSource inputImage)
        {
            byte[] srcBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4];            
            byte[] finalBytes = new byte[inputImage.PixelWidth * inputImage.PixelHeight * 4];

            inputImage.CopyPixels(srcBytes, inputImage.PixelWidth * 4, 0);            

            BrightnessContrastFilter bcFilter = new BrightnessContrastFilter(Brightness, Contrast);
            GaussianBlurFilter blurFilter = new GaussianBlurFilter(Radius);

            BitmapSource glow = blurFilter.ExecuteFilter(inputImage);

            byte[] glowBytes = new byte[glow.PixelWidth * glow.PixelHeight * 4];
            glow.CopyPixels(glowBytes, glow.PixelWidth * 4, 0);

            for (int i = 0; i < glowBytes.Length; i+=4)
            {
                byte b = glowBytes[i];
                byte g = glowBytes[i + 1];
                byte r = glowBytes[i + 2];
                byte a = glowBytes[i + 3];

                bcFilter.PerformOperation(ref b, ref g, ref r, ref a);

                finalBytes[i] = PixelBlend.BlendScreen(srcBytes[i], b);
                finalBytes[i + 1] = PixelBlend.BlendScreen(srcBytes[i + 1], g);
                finalBytes[i + 2] = PixelBlend.BlendScreen(srcBytes[i + 2], r);
                finalBytes[i + 3] = 255;
            }

            return BitmapSource.Create(inputImage.PixelWidth, inputImage.PixelHeight, 96, 96,
                inputImage.Format, null, finalBytes, inputImage.PixelWidth * 4);
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:33,代码来源:GlowEffect.cs

示例5: GrayscaleImageAdapter

        public GrayscaleImageAdapter(BitmapSource rgbSource)
        {
            if (rgbSource == null)
            {
                throw new ArgumentNullException("source");
            }

            int width = rgbSource.PixelWidth;
            int height = rgbSource.PixelHeight;
            GrayscalePixel[,] result = new GrayscalePixel[height, width];

            byte[] byteArray = new byte[height * width * 4];
            byte[] grayscaleArray = new byte[height * width];
            int stride = width * 4;
            rgbSource.CopyPixels(byteArray, stride, 0);
            int k = 0;
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    byte blue = byteArray[(i * width + j) * 4 + 0];
                    byte green = byteArray[(i * width + j) * 4 + 1];
                    byte red = byteArray[(i * width + j) * 4 + 2];
                    GrayscalePixel grayscalePixel = new GrayscalePixel(Convert.ToByte(0.2125 * red + 0.7154 * green + 0.0721 * blue));
                    result[i, j] = grayscalePixel;
                    grayscaleArray[k++] = grayscalePixel.Level;
                }
            }

            this.image = new GrayscaleImage(result);
            this.source = BitmapSource.Create(image.Width, image.Height, 96, 96, PixelFormats.Gray8, null, grayscaleArray, image.Width);
        }
开发者ID:sangelov,项目名称:Bliss,代码行数:32,代码来源:GrayscaleImageAdapter.cs

示例6: BitmapSourceToBitmap

 public static System.Drawing.Bitmap BitmapSourceToBitmap(BitmapSource srs)
 {
     System.Drawing.Bitmap temp = null;
     System.Drawing.Bitmap result;
     System.Drawing.Graphics g;
     int width = srs.PixelWidth;
     int height = srs.PixelHeight;
     int stride = width * ((srs.Format.BitsPerPixel + 7) / 8);
     byte[] bits = new byte[height * stride];
     srs.CopyPixels(bits, stride, 0);
     unsafe
     {
         fixed (byte* pB = bits)
         {
             IntPtr ptr = new IntPtr(pB);
             temp = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, ptr);
         }
     }
     // Copy the image back into a safe structure
     result = new System.Drawing.Bitmap(width, height);
     g = System.Drawing.Graphics.FromImage(result);
     g.DrawImage(temp, 0, 0);
     g.Dispose();
     return result;
 }
开发者ID:Zhevranacci,项目名称:Proxy-Printer,代码行数:25,代码来源:SourceConvert.cs

示例7: GetImageByteArray

 // get raw bytes from BitmapImage using BitmapImage.CopyPixels
 private byte[] GetImageByteArray(BitmapSource bi)
 {
     var rawStride = (bi.PixelWidth * bi.Format.BitsPerPixel + 7) / 8;
     var result = new byte[rawStride * bi.PixelHeight];
     bi.CopyPixels(result, rawStride, 0);
     return result;
 }
开发者ID:TNOCS,项目名称:csTouch,代码行数:8,代码来源:Screenshots.cs

示例8: CalculateLuminanceRGB

      private void CalculateLuminanceRGB(BitmapSource bitmap)
      {
         var width = bitmap.PixelWidth;
         var height = bitmap.PixelHeight;
         var stepX = (bitmap.Format.BitsPerPixel + 7) / 8;
         var bufferSize = width * stepX;
         var buffer = new byte[bufferSize];
         var rect = new Int32Rect(0, 0, width, 1);
         var luminanceIndex = 0;

         luminances = new byte[width * height];

         for (var curY = 0; curY < height; curY++)
         {
            bitmap.CopyPixels(rect, buffer, bufferSize, 0);
            for (var curX = 0; curX < bufferSize; curX += stepX)
            {
               var r = buffer[curX];
               var g = buffer[curX + 1];
               var b = buffer[curX + 2];
               luminances[luminanceIndex] = (byte)
                  (0.3 * r + 0.59 * g + 0.11 * b + 0.01);
               luminanceIndex++;
            }
            rect.Y++;
         }
      }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:27,代码来源:BitmapSourceLuminanceSource.cs

示例9: GetArrayOfPixels

 private static byte[] GetArrayOfPixels(BitmapSource bitmapsource)
 {
     Int32 stride = bitmapsource.PixelWidth * bitmapsource.Format.BitsPerPixel / 8;
     Int32 ByteSize = stride * bitmapsource.PixelHeight * bitmapsource.Format.BitsPerPixel / 8;
     byte[] arrayofpixel = new byte[ByteSize];
     bitmapsource.CopyPixels(arrayofpixel, stride, 0);
     return arrayofpixel;
 }
开发者ID:kiri11,项目名称:DrawTogether,代码行数:8,代码来源:BitmapProcessor.cs

示例10: ImageBuffer

 public ImageBuffer(BitmapSource bitmap)
 {
     _height = bitmap.PixelHeight;
     _width = bitmap.PixelWidth;
     _stride = _width*4;
     _buffer = new byte[_height * _stride];
     bitmap.CopyPixels(Int32Rect.Empty, _buffer, _stride, 0);
 }
开发者ID:srstrong,项目名称:NDC-Overview,代码行数:8,代码来源:ImageBuffer.cs

示例11: GetBitmap

 private Bitmap GetBitmap(BitmapSource source)
 {
     var bmp = new Bitmap(source.PixelWidth, source.PixelHeight, PixelFormat.Format32bppPArgb);
     var data = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
     source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
     bmp.UnlockBits(data);
     return bmp;
 }
开发者ID:ProjectTako,项目名称:HearthstoneTracker,代码行数:8,代码来源:CanvasToImageSourceConverter.cs

示例12: ConvertImageDataToByteArray

        static byte[] ConvertImageDataToByteArray(BitmapSource bitmap)
        {
            var stride = bitmap.PixelWidth * ((bitmap.Format.BitsPerPixel + 7) / 8);

            var imageData = new byte[bitmap.PixelHeight * stride];
            bitmap.CopyPixels(imageData, stride, 0);
            return imageData;
        }
开发者ID:fourgood,项目名称:Shapeshifter,代码行数:8,代码来源:ImagePersistenceService.cs

示例13: bitmapSourceToBitmap

 private static Bitmap bitmapSourceToBitmap(BitmapSource source)
 {
     Bitmap bmp = new Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
     BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
     source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
     bmp.UnlockBits(data);
     return bmp;
 }
开发者ID:dineshbagaria,项目名称:KinectElicitation,代码行数:8,代码来源:ImageHelper.cs

示例14: BitmapFromSource

        private System.Drawing.Bitmap BitmapFromSource(BitmapSource bitmapsource)
        {
            Bitmap bmp = new Bitmap(bitmapsource.PixelWidth, bitmapsource.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            BitmapData data = bmp.LockBits(new Rectangle(System.Drawing.Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            bitmapsource.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
            bmp.UnlockBits(data);

            return bmp;
        }
开发者ID:FRCTeam16,项目名称:FRCTeam16TargetTracking,代码行数:9,代码来源:MainWindow.xaml.cs

示例15: GetBitmap

		static Bitmap GetBitmap(BitmapSource bitmapSource)
		{
			var format = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
			Bitmap bmp = new Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight, format);
			BitmapData data = bmp.LockBits(new Rectangle(System.Drawing.Point.Empty, bmp.Size), ImageLockMode.WriteOnly, format);
			bitmapSource.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
			bmp.UnlockBits(data);
			return bmp;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:9,代码来源:ImageSourceImage.cs


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