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


C# WriteableBitmap.AddDirtyRect方法代码示例

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


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

示例1: OnRender

        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (sample == null)
                return;

            var m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
            var dpiX = m.M11;
            var dpiY = m.M22;

            int width = (int)(ActualWidth * dpiX);
            int height = (int)(ActualHeight * dpiY);

            var bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null);
            bitmap.Lock();
            using (var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, bitmap.BackBuffer, bitmap.BackBufferStride))
            {
                var skcanvas = surface.Canvas;
                skcanvas.Scale((float)dpiX, (float)dpiY);
                using (new SKAutoCanvasRestore(skcanvas, true))
                {
                    sample.Method(skcanvas, (int)ActualWidth, (int)ActualHeight);
                }
            }
            bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            bitmap.Unlock();

            drawingContext.DrawImage(bitmap, new Rect(0, 0, ActualWidth, ActualHeight));
        }
开发者ID:Core2D,项目名称:SkiaSharp,代码行数:30,代码来源:SkiaControl.cs

示例2: DissolveImages

        /// <summary>
        /// Dissolves two images using alphablending
        /// </summary>
        /// <param name="startImage">Image for percentage=0</param>
        /// <param name="endImage">Image for percentage=1</param>
        /// <param name="morphingProgress">Dissolve percentage from 0 to 1</param>
        /// <param name="outputImage">Target for image output data</param>
        public unsafe void DissolveImages(Morphing.ImageData startImage, Morphing.ImageData endImage, float percentage, WriteableBitmap outputImage)
        {
            System.Diagnostics.Debug.Assert(percentage >= 0.0f && percentage <= 1.0f);
            System.Diagnostics.Debug.Assert(startImage != null && endImage != null && outputImage != null);

            outputImage.Lock();

            int width = outputImage.PixelWidth;
            int height = outputImage.PixelHeight;
            float xStep = 1.0f / width;

            Color* outputData = (Color*)outputImage.BackBuffer;
            Parallel.For(0, outputImage.PixelHeight, yi =>
            {
                Color* outputDataPixel = outputData + yi * width;
                Color* lastOutputDataPixel = outputDataPixel + width;
                float y = (float)yi / height;
                for (float x = 0; outputDataPixel != lastOutputDataPixel; x += xStep, ++outputDataPixel)
                {
                    *outputDataPixel = Color.Lerp(startImage.Sample(x, y), endImage.Sample(x, y), percentage);
                }
            });

            outputImage.AddDirtyRect(new System.Windows.Int32Rect(0, 0, outputImage.PixelWidth, outputImage.PixelHeight));
            outputImage.Unlock();
        }
开发者ID:Wumpf,项目名称:MorphingTool,代码行数:33,代码来源:AlphaBlendDissolver.cs

示例3: UpdateNormalBitmap

		public override void UpdateNormalBitmap(WriteableBitmap bitmap, Color color) {
			unsafe {
				bitmap.Lock();
				int currentPixel = -1;
				byte* pStart = (byte*)(void*)bitmap.BackBuffer;
				double iRowUnit = (double)1 / 256;
				double iRowCurrent = 1;
				double hue = sModel.HComponent(color);
				double saturation = sModel.SComponent(color);
				for (int iRow = 0; iRow < bitmap.PixelHeight; iRow++) {

					Color hueColor = sModel.Color(hue, saturation, iRowCurrent);
					for (int iCol = 0; iCol < bitmap.PixelWidth; iCol++) {
						currentPixel++;
						*(pStart + currentPixel * 3 + 0) = hueColor.B; //Blue
						*(pStart + currentPixel * 3 + 1) = hueColor.G; //Green 
						*(pStart + currentPixel * 3 + 2) = hueColor.R; //red
					}

					iRowCurrent -= iRowUnit;

				}

				bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
				bitmap.Unlock();
			}
		}
开发者ID:paradoxfm,项目名称:ledx2,代码行数:27,代码来源:Brightness.cs

示例4: MarkFrequency

        //public void MarkFrequency(float frequency, WriteableBitmap output)
        //{
        //    if(this.soundSpectrum != null)
        //    {
        //        var renderAreaHeight = output.PixelHeight;
        //        var renderAreaWidth = output.PixelWidth;
        //        var slotIndex = (int)(Math.Round(((frequency - this.spectrumStartFrequency) / (this.spectrumEndFrequency - this.spectrumStartFrequency)) * renderAreaWidth));
        //        if(slotIndex < output.PixelWidth && slotIndex >= 0)
        //        {
        //            output.Lock();
        //            this.RenderAtSlot(slotIndex, 1.0f, output, Colors.Red);
        //            output.AddDirtyRect(new Int32Rect(slotIndex, 0, 1, renderAreaHeight));
        //            output.Unlock();
        //        }
        //    }
        //}
        public void MarkFrequency(float frequency, WriteableBitmap output)
        {
            if (this.soundSpectrum != null)
            {
                var renderAreaHeight = output.PixelHeight;
                var renderAreaWidth = output.PixelWidth;
                var diff = this.spectrumEndFrequency - this.spectrumStartFrequency;
                //var slotIndex = (int)(((frequency - this.spectrumStartFrequency) / diff) * renderAreaWidth);

                var slotIndex = (int)Math.Round(frequency / binFrequency);

                var startBin = (int)Math.Round(this.spectrumStartFrequency / binFrequency);

                slotIndex -= startBin;

                slotIndex = (int)Math.Round(((float)slotIndex / this.soundSpectrum.Length) * renderAreaWidth);

                if (slotIndex < output.PixelWidth && slotIndex >= 0)
                {
                    output.Lock();

                    this.RenderAtSlot(slotIndex, 1.0f, output, Colors.Red);

                    output.AddDirtyRect(new Int32Rect(0, 0, renderAreaWidth, renderAreaHeight));
                    //output.AddDirtyRect(new Int32Rect(slotIndex, 0, 1, renderAreaHeight));

                    output.Unlock();
                }
            }
        }
开发者ID:rychuelektryk,项目名称:UprightBassTeacher,代码行数:46,代码来源:SpectrumRenderer.cs

示例5: DrawPixel

        public virtual void DrawPixel(ref WriteableBitmap writeableBitmap, int x, int y)
        {
            int column = x;
            int row = y;

            // Reserve the back buffer for updates.
            writeableBitmap.Lock();

            unsafe
            {
                // Get a pointer to the back buffer.
                int pBackBuffer = (int)writeableBitmap.BackBuffer;

                // Find the address of the pixel to draw.
                pBackBuffer += row * writeableBitmap.BackBufferStride;
                pBackBuffer += column * 4;

                // Compute the pixel's color.
                int color_data = 255 << 16; // R
                color_data |= 255 << 8;   // G
                color_data |= 255 << 0;   // B

                // Assign the color data to the pixel.
                *((int*)pBackBuffer) = color_data;
            }

            // Specify the area of the bitmap that changed.
            writeableBitmap.AddDirtyRect(new Int32Rect(column, row, 1, 1));

            // Release the back buffer and make it available for display.
            writeableBitmap.Unlock();
        }
开发者ID:ngowdar,项目名称:TomosurgeryAlpha,代码行数:32,代码来源:IImage.cs

示例6: Window1

		public Window1()
		{
			InitializeComponent();

			SnapsToDevicePixels = true;
			SizeToContent = SizeToContent.WidthAndHeight;

			var i = new Image
			{
				Width = MandelbrotProvider.DefaultWidth,
				Height = MandelbrotProvider.DefaultHeight
			};

	

			var s = new WriteableBitmap(MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight, 
				// dpi does not seem to matter at this point
				96, 96, PixelFormats.Pbgra32, null);

			
			var shift = 0;

			Action Refresh =
				delegate
				{

					var buffer = MandelbrotProvider.DrawMandelbrotSet(shift);

					s.Lock();


					for (int j = 0; j < buffer.Length; j++)
					{
						Marshal.WriteInt32(s.BackBuffer, j * 4, unchecked((int)((uint)buffer[j] | 0xff000000)));
					}

					s.AddDirtyRect(new Int32Rect(0, 0, MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight));
					s.Unlock();
				};

			var t = new DispatcherTimer();

			t.Tick +=
				delegate
				{
					shift++;
					Refresh();

				};

			t.Interval = TimeSpan.FromMilliseconds(10);
			t.Start();

			Refresh();

			i.Source = s;

			this.Content = i;
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:59,代码来源:Window1.xaml.cs

示例7: Main

    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 2) usage();

        mapObj map = new mapObj(args[0]);

        Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name);
        for (int i = 0; i < map.numlayers; i++)
        {
        Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name);
        }

        try
        {
        WriteableBitmap mapImage = new WriteableBitmap(map.width, map.height, 96, 96, PixelFormats.Bgr32, null);
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        using (imageObj image = map.draw())
        {
            // Reserve the back buffer for updates.
            mapImage.Lock();
            try
            {
                if (image.getRawPixels(mapImage.BackBuffer) == (int)MS_RETURN_VALUE.MS_FAILURE)
                {
                    Console.WriteLine("Unable to get image contents");
                }
                // Specify the area of the bitmap that changed.
                mapImage.AddDirtyRect(new Int32Rect(0, 0, map.width, map.height));
            }
            finally
            {
                // Release the back buffer and make it available for display.
                mapImage.Unlock();
            }

            Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

            // Save the bitmap into a file.
            using (FileStream stream = new FileStream(args[1], FileMode.Create))
            {
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(mapImage));
                encoder.Save(stream);
            }
        }
        }
        catch (Exception ex)
        {
        Console.WriteLine( "\nMessage ---\n{0}", ex.Message );
        Console.WriteLine(
            "\nHelpLink ---\n{0}", ex.HelpLink );
        Console.WriteLine( "\nSource ---\n{0}", ex.Source );
        Console.WriteLine(
            "\nStackTrace ---\n{0}", ex.StackTrace );
        Console.WriteLine(
            "\nTargetSite ---\n{0}", ex.TargetSite );	}
    }
开发者ID:sbrunner,项目名称:mapserver,代码行数:59,代码来源:drawmapWPF.cs

示例8: GetImage

        public static WriteableBitmap GetImage(string path, int width, int height)
        {
            // Y,Cb,Crのbyte列を取得
            byte[] lum, cb, cr;
            int ret;
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                // byte列の確保
                lum = new byte[fs.Length / 2];
                cb = new byte[lum.Length / 2];
                cr = new byte[lum.Length / 2];

                // 読込み
                ret = fs.Read(lum, 0, lum.Length);
                ret = fs.Read(cr, 0, cr.Length);
                ret = fs.Read(cb, 0, cb.Length);
            }

            double temp;
            WriteableBitmap wbmp = new WriteableBitmap(
                width, height, 96, 96, PixelFormats.Bgr32, null);

            wbmp.Lock();

            byte[] buf = new byte[wbmp.PixelWidth * wbmp.PixelHeight * 4];
            for (int i = 0; i < buf.Length; i += 4)
            {
                int index = i / 4;
                // B
                temp = 1.164 * (lum[index] - 16) + 2.018 * (cr[index / 2] - 128);
                if (temp > 255) temp = 255;
                if (temp < 0) temp = 0;
                buf[i] = (byte)temp;

                // G
                temp = 1.164 * (lum[index] - 16) - 0.391 * (cr[index / 2] - 128) - 0.813 * (cb[index / 2] - 128);
                if (temp > 255) temp = 255;
                if (temp < 0) temp = 0;
                buf[i + 1] = (byte)temp;

                // R
                temp = 1.164 * (lum[index] - 16) + 1.596 * (cb[index / 2] - 128);
                if (temp > 255) temp = 255;
                if (temp < 0) temp = 0;
                buf[i + 2] = (byte)temp;
            }

            Marshal.Copy(buf, 0, wbmp.BackBuffer, buf.Length);

            wbmp.AddDirtyRect(new Int32Rect(0, 0, wbmp.PixelWidth, wbmp.PixelHeight));
            wbmp.Unlock();

            return wbmp;
        }
开发者ID:kon0524,项目名称:YuvViewer,代码行数:54,代码来源:Yuv422.cs

示例9: TransferBytesToWriteableBitmap

 public static void TransferBytesToWriteableBitmap(WriteableBitmap bitmap, ushort[] pixels)
 {
     bitmap.Lock();
       unsafe
       {
     ushort* bPtr = (ushort*)bitmap.BackBuffer;
     foreach (ushort pixel in pixels)
     {
       *bPtr++ = pixel;
     }
       }
       bitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
       bitmap.Unlock();
 }
开发者ID:cristiandonosoc,项目名称:GBSharp,代码行数:14,代码来源:Utils.cs

示例10: Page1

		public Page1()
		{
			// Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

			InitializeComponent();

			var i = new Image();

			var s = new WriteableBitmap(600, 600, 96, 96, PixelFormats.Pbgra32, null);
			Plasma.generatePlasma(600, 600);
			var shift = 0;

			Action Refresh =
				delegate
				{

					var buffer = Plasma.shiftPlasma(shift);

					s.Lock();


					for (int j = 0; j < buffer.Length; j++)
					{
						Marshal.WriteInt32(s.BackBuffer, j * 4, unchecked((int)(buffer[j] | 0xff000000)));
					}

					s.AddDirtyRect(new Int32Rect(0, 0, 600, 600));
					s.Unlock();
				};

			var t = new DispatcherTimer();

			t.Tick +=
				delegate
				{
					shift++;
					Refresh();

				};

			t.Interval = TimeSpan.FromMilliseconds(10);
			t.Start();

			Refresh();

			i.Source = s;

			this.Content = i;
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:49,代码来源:Page1.xaml.cs

示例11: AddFrame

 private void AddFrame(AnimatedGifEncoder encoder)
 {
     var rtb = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32);
     rtb.Render(this);
     var bitmap = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32, null);
     bitmap.FillRectangle(0, 0, bitmap.PixelWidth, bitmap.PixelWidth, Colors.Wheat);
     bitmap.Lock();
     rtb.CopyPixels(
         new Int32Rect(0, 0, rtb.PixelWidth, rtb.PixelHeight),
         bitmap.BackBuffer,
         bitmap.BackBufferStride * bitmap.PixelHeight, bitmap.BackBufferStride);
     bitmap.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
     bitmap.Unlock();
     encoder.AddFrame(bitmap);
 }
开发者ID:TheFabFab,项目名称:ObservableLinq,代码行数:15,代码来源:MainWindow.xaml.cs

示例12: Window1

		public Window1()
		{
			InitializeComponent();

			var i = new Image();

			var s = new WriteableBitmap(600, 600, 96, 96, PixelFormats.Pbgra32, null);
			Plasma.generatePlasma(600, 600);
			var shift = 0;

			Action Refresh =
				delegate
				{

					var buffer = Plasma.shiftPlasma(shift);

					s.Lock();


					for (int j = 0; j < buffer.Length; j++)
					{
						Marshal.WriteInt32(s.BackBuffer, j * 4, unchecked((int)(buffer[j] | 0xff000000) ));
					}

					s.AddDirtyRect(new Int32Rect(0, 0, 600, 600));
					s.Unlock();
				};

			var t = new DispatcherTimer();

			t.Tick +=
				delegate
				{
					shift++;
					Refresh();

				};

			t.Interval = TimeSpan.FromMilliseconds(10);
			t.Start();

			Refresh();

			i.Source = s;

			this.Content = i;
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:47,代码来源:Window1.xaml.cs

示例13: UpdateColorPlaneBitmap

		public override void UpdateColorPlaneBitmap(WriteableBitmap bitmap, int normalComponentValue) {
			unsafe {
				bitmap.Lock();
				int currentPixel = -1;
				byte* pStart = (byte*)(void*)bitmap.BackBuffer;
				for (int iRow = 0; iRow < bitmap.PixelHeight; iRow++) {
					for (int iCol = 0; iCol < bitmap.PixelWidth; iCol++) {
						currentPixel++;
						*(pStart + currentPixel * 3 + 0) = (byte)(iCol); //Blue
						*(pStart + currentPixel * 3 + 1) = (byte)(255 - iRow); //Green 
						*(pStart + currentPixel * 3 + 2) = (byte)normalComponentValue; //red
					}
				}
				bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
				bitmap.Unlock();
			}
		}
开发者ID:paradoxfm,项目名称:ledx2,代码行数:17,代码来源:Red.cs

示例14: Paint

        public void Paint(SceneMetaData sceneMeta, WriteableBitmap b)
        {
            b.Lock();

            unsafe
            {
                short* pLabelRow = (short*)sceneMeta.SceneMapPtr;

                int nTexMapX = b.BackBufferStride;
                byte* pTexRow = (byte*)b.BackBuffer + sceneMeta.YOffset * nTexMapX;

                for (int y = 0; y < sceneMeta.YRes; y++)
                {
                    short* pLabel = pLabelRow;
                    byte* pTex = pTexRow + sceneMeta.XOffset;

                    for (int x = 0; x < sceneMeta.XRes; x++)
                    {
                        //var label = sceneMeta.GetLabel((uint) x, (uint) y);
                        var label = (*pLabel);
                        if (label != 0)
                        {
                            var c = _colors[label%_colors.Length];
                            pTex[0] = c.B;  // B
                            pTex[1] = c.G;  // G
                            pTex[2] = c.R;  // R
                            pTex[3] = c.A;  // A
                        }
                        else
                        {
                            pTex[0] = 0;  // B
                            pTex[1] = 0;  // G
                            pTex[2] = 0;  // R
                            pTex[3] = 0;  // A
                        }
                        pLabel++;
                        pTex += 4;
                    }
                    pLabelRow += sceneMeta.XRes;
                    pTexRow += nTexMapX;
                }
            }
            b.AddDirtyRect(new Int32Rect(0, 0, b.PixelWidth, b.PixelHeight));
            b.Unlock();
        }
开发者ID:Chicoo,项目名称:KinectOnOpenNI,代码行数:45,代码来源:SceneMap.cs

示例15: MainWindow

        public MainWindow()
        {
            InitializeComponent();
            AntiAlias = false;
            var wb = new WriteableBitmap(ViewModel.CellBoard.Width, ViewModel.CellBoard.Height, 96, 96, PixelFormats.Bgr32, null);
            Canvas.Source = wb;

            CompositionTarget.Rendering += (sender, args) =>
            {
                wb.Lock();
                unsafe
                {
                    CellBoard.Render((uint*)wb.BackBuffer, wb.BackBufferStride, ViewModel.CellBoard.Width, ViewModel.CellBoard.Height, ViewModel.CellBoard.Cells);
                }
                wb.AddDirtyRect(new Int32Rect(0, 0, wb.PixelWidth, wb.PixelHeight));
                wb.Unlock();
            };
        }
开发者ID:runicalp,项目名称:LifeGame,代码行数:18,代码来源:MainWindow.xaml.cs


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