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


C# BitmapImage.CopyPixels方法代码示例

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


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

示例1: GetSinglePixel

 static Color GetSinglePixel(BitmapImage source, int x, int y)
 {
     int stride = (source.Format.BitsPerPixel + 7) / 8;
     byte[] pixels = new byte[stride];
     source.CopyPixels(new Int32Rect(x, y, 1, 1), pixels, stride, 0);
     return Color.FromArgb(pixels[3], pixels[0], pixels[1], pixels[2]);
 }
开发者ID:trigger-death,项目名称:TriggersPC,代码行数:7,代码来源:PokemonDatabase.cs

示例2: openButton_Click

        private void openButton_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();
            if (dlg.ShowDialog(this).Value)
            {
                try
                {
                    if (new FileInfo(dlg.FileName).Extension.ToLower() == ".bmpc")
                    {
                        var image = new ImageBMPC(dlg.FileName, false, null);
                        var writable = new WriteableBitmap(image.Size.Width, image.Size.Height, 96, 96, PixelFormats.Bgra32, null);
                        int stride = (image.Size.Width * 32 + 7) / 8;

                        // Flip RB Color bits
                        var data = new byte[image.Mipmaps[0].Data.LongLength];
                        image.Mipmaps[0].Data.CopyTo(data, 0);
                        for (int i2 = 0; i2 != data.Length; i2 += 4)
                        {
                            byte c = data[i2];
                            data[i2] = data[i2+2];
                            data[i2+2] = c;
                        }

                        writable.WritePixels(new Int32Rect(0, 0, image.Size.Width, image.Size.Height), data, stride, 0);
                        dstImage.Source = writable;
                    }
                    else
                    {
                        // Load binary data
                        var bitmap = new BitmapImage(new Uri(dlg.FileName, UriKind.Absolute));
                        int stride = (bitmap.PixelWidth * bitmap.Format.BitsPerPixel + 7) / 8;
                        srcData = new byte[bitmap.PixelWidth * stride];
                        dstData = new byte[bitmap.PixelWidth * stride];
                        bitmap.CopyPixels(srcData, stride, 0);
                        bitmap.CopyPixels(dstData, stride, 0);

                        // Get image atributes
                        var ext = new FileInfo(dlg.FileName).Extension.ToLower();
                        width = bitmap.PixelWidth;
                        height = bitmap.PixelHeight;

                        // Display images
                        var w = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96, PixelFormats.Bgra32, null);
                        w.WritePixels(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight), srcData, stride, 0);
                        dstImage.Source = w;
                        srcImage.Source = bitmap;

                        processesImage();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
开发者ID:reignstudios,项目名称:ReignSDK,代码行数:56,代码来源:MainWindow.xaml.cs

示例3: btnFilter_Click

 private void btnFilter_Click(object sender, RoutedEventArgs e)
 {
     if (_pointCollection[0].X != 0 || _pointCollection[_pointCollection.Count - 1].X != 255)
     {
         MessageBox.Show("You have to set the initial and final values of X!");
         return;
     }
     if (imgOriginal.Source == null)
     {
         MessageBox.Show("You have to load the image first!");
         return;
     }
     ImageSource ims = imgOriginal.Source;
     _bitmapImage = (BitmapImage)ims;
     _height = _bitmapImage.PixelHeight;
     _width = _bitmapImage.PixelWidth;
     _rawStride = (_width * _bitmapImage.Format.BitsPerPixel + 7) / 8;
     _pixelData = new byte[_rawStride * _height];
     _bitmapImage.CopyPixels(_pixelData, _rawStride, 0);
     int[] function = new int[256];
     for (int i = 0; i < 256; i++)
     {
         bool isKnown = false;
         foreach (Point p in _pointCollection)
         {
             if (i == (int)p.X)
             {
                 isKnown = true;
                 function[i] = (int)(255 - p.Y);
                 break;
             }
         }
         if (isKnown)
         {
             continue;
         }
         for (int j = 0; j < _pointCollection.Count; j++)
         {
             if (_pointCollection[j].X < i && _pointCollection[j + 1].X >= i)
             {
                 function[i] = 255 - ((int)_pointCollection[j].Y + ((int)_pointCollection[j + 1].Y - (int)_pointCollection[j].Y) * (i - (int)_pointCollection[j].X) / ((int)_pointCollection[j + 1].X - (int)_pointCollection[j].X));
                 break;
             }
         }
     }
     for (int y = 0; y < _height; y++)
     {
         int yIndex = y * _rawStride;
         for (int x = 0; x < _rawStride; x+=3)
         {
             if (x+yIndex+2 > _pixelData.Length-1)
                 break;
             _pixelData[x + yIndex] = (byte)function[_pixelData[x + yIndex]];
             _pixelData[x + yIndex + 1] = (byte)function[_pixelData[x + yIndex + 1]];
             _pixelData[x + yIndex + 2] = (byte)function[_pixelData[x + yIndex + 2]];
         }
     }
     _filteredBitmap = BitmapSource.Create(_width, _height, 96, 96, _bitmapImage.Format, _bitmapImage.Palette, _pixelData, _rawStride);
     imgFiltered.Source = _filteredBitmap;
 }
开发者ID:pmichna,项目名称:1-1_Filter,代码行数:60,代码来源:MainWindow.xaml.cs

示例4: GetHashCode

        public List<string> GetHashCode(BitmapImage bitmap)
        {//takes a bitmap and translates it into the hashcode list
            List<string> hashCode= new List<string>();

            int stride = bitmap.PixelWidth * (bitmap.Format.BitsPerPixel / 8);
            for (int i = 0; i < bitmap.PixelHeight; i++)//divides an image into rows 
            {
                string row="";
                for (int x = 0; x < bitmap.PixelWidth; x++)//iterates through each pixel in the row
                {
                    byte[] pixel = new byte[bitmap.PixelHeight];//holds color values of a single pixel
                    bitmap.CopyPixels(new Int32Rect(x, i, 1, 1), pixel, stride, 0);//assigns color values of a single pixel to the pixel array
                    Color singlePixel = new Color();//creates new color objects and assigns the color values found in pixel array to it
                    singlePixel.B = pixel[0];
                    singlePixel.G = pixel[1];
                    singlePixel.R = pixel[2];
                    singlePixel.A = pixel[3];
                    row += singlePixel.GetHashCode().ToString();//converst the color value into the hashcode and converts it to the string
                }
                hashCode.Add(row);
                if (i % 20 == 0)//Updates programm only after each tenth iteration, this makes program run a bit faster
                UpdatePRogress();
            }
            return hashCode;
        }
开发者ID:iskenxan,项目名称:ImageComparer,代码行数:25,代码来源:GetPixelStrings.cs

示例5: BitmapImageToBitmap

        public static System.Drawing.Bitmap BitmapImageToBitmap(BitmapImage source)
        {
            Bitmap bmp = new Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
            bmp.UnlockBits(data);
            return bmp;
            /*
            System.Drawing.Bitmap btm = null;
            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);
                    btm = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, ptr);
                }
            }

            return btm;*/
        }
开发者ID:sagar-sm,项目名称:wpf-winforms-convertor,代码行数:28,代码来源:Compatibility.cs

示例6: ConvertBitmapImageToByteArray

 private byte[] ConvertBitmapImageToByteArray(BitmapImage bitmap)
 {
     int stride = bitmap.PixelWidth * 4;
     int size = bitmap.PixelHeight * stride;
     byte[] pixels = new byte[size];
     bitmap.CopyPixels(pixels, stride, 0);
     return pixels;
 }
开发者ID:Jeffrie-Rubner,项目名称:Capstone,代码行数:8,代码来源:ColorScaleAspectDeterminer.cs

示例7: ReadAllBytes

        private byte[] ReadAllBytes(BitmapImage img)
        {
            var stride = img.PixelWidth * (img.Format.BitsPerPixel / 8);
            var pixels = new byte[stride * img.PixelHeight];

            img.CopyPixels(pixels, stride, 0);

            return pixels;
        }
开发者ID:zerkms,项目名称:shary,代码行数:9,代码来源:TransparencyCalc.cs

示例8: ConvertBitmapToOneTrueDpi

        public static BitmapSource ConvertBitmapToOneTrueDpi(BitmapImage bitmapImage) {
            var width = bitmapImage.PixelWidth;
            var height = bitmapImage.PixelHeight;

            var stride = width * bitmapImage.Format.BitsPerPixel;
            var pixelData = new byte[stride * height];
            bitmapImage.CopyPixels(pixelData, stride, 0);

            return BitmapSource.Create(width, height, OneTrueDpi, OneTrueDpi, bitmapImage.Format, null, pixelData, stride);
        }
开发者ID:gro-ove,项目名称:actools,代码行数:10,代码来源:UriToCachedImageConverter.cs

示例9: LoadPixelData

        /// <summary>
        /// Obtains the image data once it is loaded
        /// </summary>
        private void LoadPixelData()
        {
            var bitmapImage = new BitmapImage(new Uri("pack://application:,,,/Examples/HistogramDemo/hare.jpg"));

            int stride = ((bitmapImage.PixelWidth * bitmapImage.Format.BitsPerPixel) + 7) / 8;
            var pixelByteArray = new byte[bitmapImage.PixelHeight * stride];
            bitmapImage.CopyPixels(pixelByteArray, stride, 0);
            this.pixelData = new int[pixelByteArray.Length / 4];
            Buffer.BlockCopy(pixelByteArray, 0, this.pixelData, 0, pixelByteArray.Length);
        }
开发者ID:Celderon,项目名称:oxyplot,代码行数:13,代码来源:MainWindow.xaml.cs

示例10: MakeBitmap

 public ImageContext MakeBitmap()
 {
     BitmapImage myBitmapImage = new BitmapImage();
     myBitmapImage.BeginInit();
     myBitmapImage.UriSource = new Uri(@text1.Text);
     myBitmapImage.EndInit();
     myImage.Source = myBitmapImage;
     ImageContext inSource = new ImageContext(myBitmapImage.PixelHeight, myBitmapImage.PixelWidth, myBitmapImage.Format);
     myBitmapImage.CopyPixels(inSource.PixelByteArray, inSource.NStride, 0);
     return inSource;
 }
开发者ID:PokrovskiyEgor,项目名称:ForImg2,代码行数:11,代码来源:MainWindow.xaml.cs

示例11: Load

        public byte[] Load(string path, out int width, out int height, out int stride)
        {
            var source = new BitmapImage(new Uri("pack://application:,,,/" + path));
            width = source.PixelWidth;
            height = source.PixelHeight;

            stride = 500;
            var bytes = new byte[stride * height];
            source.CopyPixels(bytes, stride, 0);

            return bytes;
        }
开发者ID:vidstige,项目名称:VectorUI,代码行数:12,代码来源:MainViewModel.cs

示例12: ConvertBitmapTo96Dpi

        internal static BitmapSource ConvertBitmapTo96Dpi(BitmapImage bitmap_image)
        {
            const double dpi = 96;
            var width = bitmap_image.PixelWidth;
            var height = bitmap_image.PixelHeight;
            var stride = (bitmap_image.Format.BitsPerPixel * width + 7) / 8;
            var pixel_data = new byte[stride * height];
            bitmap_image.CopyPixels(pixel_data, stride, 0);

            var rtn = BitmapSource.Create(width, height, dpi, dpi, bitmap_image.Format, null, pixel_data, stride);
            if (rtn.CanFreeze)
                rtn.Freeze();

            return rtn;
        }
开发者ID:heartszhang,项目名称:WeiZhi3,代码行数:15,代码来源:ImageLocalCacheBase.cs

示例13: ProcessImage

		private void ProcessImage(BitmapImage bmp)
		{
			byte[] pixels = new byte[bmp.PixelWidth * bmp.PixelHeight * 4];
			bmp.CopyPixels(pixels, bmp.PixelWidth * 4, 0);

			for (int i = 0; i < pixels.Length; )
			{
				//BGRA
				blues[pixels[i++]]++;
				greens[pixels[i++]]++;
				reds[pixels[i++]]++;
				i++;
			}

			CreateHistograms();
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:16,代码来源:Window1.xaml.cs

示例14: MakeBitmap

        public void MakeBitmap()
        {
            BitmapImage myBitmapImage = new BitmapImage();
            myBitmapImage.BeginInit();
            myBitmapImage.UriSource = new Uri(@text1.Text);
            myBitmapImage.EndInit();
            myImage.Source = myBitmapImage;
            //
            height = myBitmapImage.PixelHeight;
            width = myBitmapImage.PixelWidth;
            imageFormat = myBitmapImage.Format;
            nStride = (myBitmapImage.PixelWidth * imageFormat.BitsPerPixel + 7) / 8;

            pixelByteArraySize = myBitmapImage.PixelHeight * nStride;
            pixelByteArrayIn = new byte[pixelByteArraySize];
            myBitmapImage.CopyPixels(pixelByteArrayIn, nStride, 0);
        }
开发者ID:PokrovskiyEgor,项目名称:ForImg2,代码行数:17,代码来源:logic.cs

示例15: LoadImage

        private void LoadImage()
        {
            this.originalImage = new BitmapImage();
            originalImage.BeginInit();
            originalImage.UriSource = new Uri(FilePath.Text, UriKind.Absolute);

            originalImage.EndInit();

            OriginalImage.Source = originalImage;
            ModifiedImage.Source = originalImage;

            int[] pixelData = new int[originalImage.PixelHeight*originalImage.PixelWidth];
            int widthInByte = 4*originalImage.PixelWidth;
            originalImage.CopyPixels(pixelData, widthInByte, 0);
            DrawHistogram(pixelData, "ORIGINAL");
            DrawHistogram(pixelData, "MODIFIED");
        }
开发者ID:romannort,项目名称:Dsp,代码行数:17,代码来源:MainWindow.xaml.cs


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