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


C# WriteableBitmap.WritePixels方法代码示例

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


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

示例1: CreatePaletteBrush

		public static Brush CreatePaletteBrush(IPalette palette, int width = 256)
		{
			const double dpi = 96;

			WriteableBitmap bmp = new WriteableBitmap(width, 1,
				dpi, dpi,
				PixelFormats.Bgra32, null);

			int[] pixels = new int[width];
			for (int i = 0; i < width; i++)
			{
				double ratio = i / ((double)width);
				Color color = palette.GetColor(ratio);
				int argb = color.ToArgb();
				pixels[i] = argb;
			}

			bmp.WritePixels(
				new Int32Rect(0, 0, width, 1),
				pixels,
				bmp.BackBufferStride,
				0);

			return new ImageBrush(bmp);
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:25,代码来源:ImageHelper.cs

示例2: BuildColorBitmap

        public static WriteableBitmap BuildColorBitmap(CTSliceInfo ct,
                                                       byte[,]     normalizedPixelBuffer)
        {
            byte[] imageDataArray = new byte[ct.RowCount * ct.ColumnCount * 4];

            int i = 0;
            for (int r = 0; r != ct.RowCount; ++r)
            {
                for (int c = 0; c != ct.ColumnCount; ++c)
                {
                    byte aGrayValue = normalizedPixelBuffer[r, c];

                    // Black/White image: all RGB values are set to same value
                    // Alpha value is set to 255
                    imageDataArray[i * 4] = aGrayValue;
                    imageDataArray[i * 4 + 1] = aGrayValue;
                    imageDataArray[i * 4 + 2] = aGrayValue;
                    imageDataArray[i * 4 + 3] = 255;

                    ++i;
                }
            }

            // Allocate the Bitmap
            WriteableBitmap bitmap = new WriteableBitmap(ct.ColumnCount, ct.RowCount, 96, 96, PixelFormats.Pbgra32, null);

            // Write the Pixels
            Int32Rect imageRectangle = new Int32Rect(0, 0, ct.ColumnCount, ct.RowCount);
            int imageStride = ct.ColumnCount * bitmap.Format.BitsPerPixel / 8;
            bitmap.WritePixels(imageRectangle, imageDataArray, imageStride, 0);

            return bitmap;
        }
开发者ID:Kri-Ol,项目名称:DCMview,代码行数:33,代码来源:CTSliceHelpers.cs

示例3: CreateImage

        public unsafe void CreateImage(WriteableBitmap target, IntPtr pointer)
        {
            Int32Rect rectangle = default(Int32Rect);
            target.Dispatcher.Invoke(new Action(() =>
            {
                rectangle = new Int32Rect(0, 0, target.PixelWidth, target.PixelHeight);
            }));

            this.CreateHistogram(pointer, rectangle.Width, rectangle.Height);
            var pixelcount = rectangle.Width * rectangle.Height;
            var buffer = new byte[pixelcount * 3];
            try
            {
                ushort* pDepth = (ushort*)pointer;
                for (int index = 0; index < pixelcount; index++)
                {
                    byte pixel = (byte)histogram.GetValue(*pDepth);
                    buffer[index * 3] = pixel;
                    buffer[index * 3 + 1] = pixel;
                    buffer[index * 3 + 2] = pixel;
                    pDepth++;
                }
            }
            catch (AccessViolationException)
            { }
            catch (SEHException)
            { }

            target.Dispatcher.Invoke(new Action(() =>
                {
                    target.Lock();
                    target.WritePixels(rectangle, buffer, rectangle.Width * 3, 0);
                    target.Unlock();
                }));
        }
开发者ID:aabrohi,项目名称:kinect-kollage,代码行数:35,代码来源:DepthImageSourceFactory.cs

示例4: writeImageToFile

        public void writeImageToFile()
        {
            writeNo++;
            bitmap = new WriteableBitmap(width, height, 96.0, 96.0, PixelFormats.Bgr32, null);
            bitmap.WritePixels(
                        new Int32Rect(0, 0, this.bitmap.PixelWidth, this.bitmap.PixelHeight),
                        this.imageData,
                        this.bitmap.PixelWidth * sizeof(int),
                        0);
            // create a png bitmap encoder which knows how to save a .png file
            BitmapEncoder encoder = new PngBitmapEncoder();

            // create frame from the writable bitmap and add to encoder
            encoder.Frames.Add(BitmapFrame.Create(this.bitmap));

            string path =  imageDirectory + "\\" + fileSeriesName + "-" + writeNo + ".png";

            // write the new file to disk
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Create))
                {
                    encoder.Save(fs);
                    Console.WriteLine();
                    Console.WriteLine("Kinect image " + writeNo + " saved to disk @ " + System.DateTime.Now);
                }
            }
            catch (IOException)
            {
                Console.WriteLine("*** Problem saving image file on write number " + writeNo);
            }
        }
开发者ID:janslow,项目名称:cs-a-group,代码行数:32,代码来源:VisualLightWriter.cs

示例5: FillBitmap

        /// <summary>
        /// 
        /// </summary>
        /// <param name="colorFrame"></param>
        /// <param name="headList"></param>
        private void FillBitmap( ColorImageFrame colorFrame, List<SkeletonPoint> headList )
        {
            // 描画の準備
            using ( var drawContecxt = drawVisual.RenderOpen() ) {
                // 画像情報をバッファにコピー
                colorFrame.CopyPixelDataTo( pixelBuffer );

                // カメラの画像情報から、背景のビットマップを作成し描画する
                var backgroundImage = new WriteableBitmap( colorFrame.Width, colorFrame.Height, 96, 96,
                    PixelFormats.Bgr32, null );
                backgroundImage.WritePixels( new Int32Rect( 0, 0, colorFrame.Width, colorFrame.Height ),
                    pixelBuffer, colorFrame.Width * 4, 0 );
                drawContecxt.DrawImage( backgroundImage,
                    new Rect( 0, 0, colorFrame.Width, colorFrame.Height ) );

                // 頭の位置にマスク画像を表示する
                foreach ( SkeletonPoint head in headList ) {
                    ColorImagePoint headPoint = kinect.MapSkeletonPointToColor( head, rgbFormat );
                    drawContecxt.DrawImage( maskImage,
                        new Rect( headPoint.X - 64, headPoint.Y - 64, 128, 128 ) );
                }
            }

            // 画面に表示するビットマップに描画する
            bmpBuffer.Render( drawVisual );
        }
开发者ID:kaorun55,项目名称:kinectionjp,代码行数:31,代码来源:MainWindow.xaml.cs

示例6: ResetOverlay

        public void ResetOverlay()
        {
            if (_Image != null)
            {
                _Overlay = new WriteableBitmap(_Image.PixelWidth, _Image.PixelHeight, _Image.DpiX, _Image.DpiY,
                                               _Image.Format, _Image.Palette);

                int stride = _Overlay.BackBufferStride;
                int numpixelbytes = _Overlay.PixelHeight*_Overlay.PixelWidth*_Overlay.Format.BitsPerPixel/8;
                var pixels = new byte[numpixelbytes];

                //for (int x = 0; x < _Overlay.PixelWidth; x++)
                //{
                //    for (int y = 0; y < _Overlay.PixelHeight; y++)
                //    {
                //        pixels[x * 4 + y * stride] = (byte)0;
                //        pixels[x * 4 + y * stride + 1] = (byte)0;
                //        pixels[x * 4 + y * stride + 2] = (byte)0;
                //        pixels[x * 4 + y * stride + 3] = (byte)0;
                //    }
                //}

                _Image.CopyPixels(pixels, stride, 0);
                _Overlay.WritePixels(new Int32Rect(0, 0, _Overlay.PixelWidth, _Overlay.PixelHeight), pixels,
                                     _Overlay.PixelWidth*_Overlay.Format.BitsPerPixel/8, 0);
            }
            RaisePropertyChanged("Overlay");
        }
开发者ID:Kyphis,项目名称:Terraria-Map-Editor,代码行数:28,代码来源:WorldImage.cs

示例7: RecordedVideoFrame

        public RecordedVideoFrame(ColorImageFrame colorFrame)
        {
            if (colorFrame != null)
            {
                byte[] bits = new byte[colorFrame.PixelDataLength];
                colorFrame.CopyPixelDataTo(bits);

                int BytesPerPixel = colorFrame.BytesPerPixel;
                int Width = colorFrame.Width;
                int Height = colorFrame.Height;

                var bmp = new WriteableBitmap(Width, Height, 96, 96, PixelFormats.Bgr32, null);
                bmp.WritePixels(new System.Windows.Int32Rect(0, 0, Width, Height), bits, Width * BytesPerPixel, 0);
                JpegBitmapEncoder jpeg = new JpegBitmapEncoder();
                jpeg.Frames.Add(BitmapFrame.Create(bmp));
                var SaveStream = new MemoryStream();
                jpeg.Save(SaveStream);
                SaveStream.Flush();
                JpegData = SaveStream.ToArray();
            }
            else
            {
                return;
            }
        }
开发者ID:pi11e,项目名称:KinectHTML5,代码行数:25,代码来源:RecordedVideoFrame.cs

示例8: Window_Loaded

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WriteableBitmap bmp = new WriteableBitmap(1600, 900, 96, 96, PixelFormats.Bgra32, null),
            outImg = new WriteableBitmap(bmp);
              Iterator iter = new Iterator(bmp, new MandelbrotIterFunc(), 1e5, 2000) {
            SampleCount = 3
              };

              //outImg.Freeze();

              OutputImg.Source = bmp;

              byte[] pxs = new byte[bmp.PixelWidth * bmp.PixelHeight * 4];

              for (int i = 0; i + 3 < pxs.Length; i += 4) {
            pxs[i] = 0;
            pxs[i + 1] = 0;
            pxs[i + 2] = 0;
            pxs[i + 3] = 255;
              }

              bmp.WritePixels(new Int32Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight), pxs, bmp.PixelWidth * 4, 0);

              iter.Width = bmp.PixelWidth;
              iter.Height = bmp.PixelHeight;

              iter.Start();
        }
开发者ID:rookie1024,项目名称:JuliaSet,代码行数:28,代码来源:MainWindow.xaml.cs

示例9: CreateImage

        public unsafe void CreateImage(WriteableBitmap target, IntPtr pointer)
        {
            Int32Rect rectangle = default(Int32Rect);
            target.Dispatcher.Invoke(new Action(() => 
                {
                    rectangle = new Int32Rect(0, 0, target.PixelWidth, target.PixelHeight);
                }));

            byte* pImage = (byte*)pointer.ToPointer();

            var pixelCount = rectangle.Width * rectangle.Height;
            var buffer = new byte[pixelCount * 3];

            for (int index = 0; index < pixelCount; index++)
            {
                buffer[index * 3] = pImage[2];
                buffer[index * 3 + 1] = pImage[1];
                buffer[index * 3 + 2] = pImage[0];
                pImage += 3;
            }

            target.Dispatcher.Invoke(new Action(() =>
            {
                target.Lock();
                target.WritePixels(rectangle, buffer, rectangle.Width * 3, 0);
                target.Unlock();
            }));
        }
开发者ID:aabrohi,项目名称:kinect-kollage,代码行数:28,代码来源:RgbImageSourceFactory.cs

示例10: 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

示例11: Render

        public WriteableBitmap Render(int[] values)
        {
            if (values.Length != this.pixels.Length)
            {
                throw new ArgumentException("Number of raw values must equal width*height");
            }

            // Convert raw values to ARGB format pixels.
            this.ConvertToPixels(values);

            // Copy pixels to frame buffer.
            var bitmap = new WriteableBitmap(   this.width,
                                                this.height,
                                                0,
                                                0,
                                                PixelFormats.Pbgra32,
                                                null);
            int widthInBytes = 4 * this.width;
            var sourceRect = new Int32Rect(0, 0, this.width, this.height);
            bitmap.WritePixels( sourceRect,
                                pixels,
                                widthInBytes,
                                0);

            return bitmap;
        }
开发者ID:thomasbratt,项目名称:HodgePodgeScreensaver,代码行数:26,代码来源:RenderToBitmap.cs

示例12: RenderMaterial

        public void RenderMaterial()
        {
            int width = (int)Width;
            int height = (int)Height;

            byte[] pixels = new byte[4 * height * width];
            WriteableBitmap writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);

            for (int p=0; p<width*height; p++)
            {
                Colour fillColour = _Material._DiffuseColour;
                fillColour.Clamp(0, 1);
                pixels[p*4] = (byte)(fillColour._Blue * 255.99f);
                pixels[p*4+1] = (byte)(fillColour._Green * 255.99f); 
                pixels[p*4+2] = (byte)(fillColour._Red * 255.99f); 
                pixels[p*4+3] = 255;
            }

            Int32Rect rect = new Int32Rect(0, 0, width, height);

            writeableBitmap.WritePixels(rect, pixels, width * 4, (int)0);

            MaterialImage.Source = writeableBitmap;

        }
开发者ID:dom767,项目名称:woofractal,代码行数:25,代码来源:MaterialControl.xaml.cs

示例13: ColourImage

        public static ImageSource ColourImage(string resource, SolidColorBrush brush)
        {
            // Copy pixel colour values from existing image.
            // (This loads them from an embedded resource. BitmapDecoder can work with any Stream, though.)
            //StreamResourceInfo x = Application.GetResourceStream(new Uri(BaseUriHelper.GetBaseUri(this), "Image.png"));
            var uri = new Uri("pack://application:,,,/LightBlue.MultiHost;component/" + resource);
            StreamResourceInfo x = Application.GetResourceStream(uri);
            BitmapDecoder dec = BitmapDecoder.Create(x.Stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
            BitmapFrame image = dec.Frames[0];

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

            // Modify the alpha pixels
            for (int i = 0; i < pixels.Length / 4; ++i)
            {
                byte a = pixels[i * 4 + 3];

                if (a != 0)
                {
                    pixels[i * 4] = brush.Color.B;
                    pixels[i * 4 + 1] = brush.Color.G;
                    pixels[i * 4 + 2] = brush.Color.R;
                }
            }

            // Write the modified pixels into a new bitmap and use that as the source of an Image
            var bmp = new WriteableBitmap(image.PixelWidth, image.PixelHeight, image.DpiX, image.DpiY, PixelFormats.Pbgra32, null);
            bmp.WritePixels(new Int32Rect(0, 0, image.PixelWidth, image.PixelHeight), pixels, image.PixelWidth * 4, 0);
            return bmp;
        }
开发者ID:johndalin,项目名称:LightBlue,代码行数:31,代码来源:ImageUtil.cs

示例14: ToBitmapSource

        public BitmapSource ToBitmapSource(int width, int height, double dpiX, double dpiY)
        {
            var result = new WriteableBitmap(width, height, dpiX, dpiY, workingFormat, null);

            result.WritePixels(new Int32Rect(0, 0, result.PixelWidth, result.PixelHeight), buffer, sizeof(float) * floatStride, 0);

            return result;
        }
开发者ID:EFanZh,项目名称:EFanZh,代码行数:8,代码来源:RgbaBitmapBuffer.cs

示例15: PerlinTestWindow

 public PerlinTestWindow()
 {
     InitializeComponent();
     WriteableBitmap wb = new WriteableBitmap(256, 256, 96.0, 96.0, PixelFormats.Gray8, null);
     PerlinNoise noise = new PerlinNoise(99);
     wb.WritePixels(new Int32Rect(0, 0, 256, 256), noise.GetPixels(256, 256), 256, 0);
     MainImage.Source = wb;
 }
开发者ID:Hobble,项目名称:HubrisEditor,代码行数:8,代码来源:PerlinTestWindow.xaml.cs


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