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


C# WriteableBitmap.Clear方法代码示例

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


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

示例1: BaseTool

 protected BaseTool(WorldViewModel worldViewModel)
 {
     _wvm = worldViewModel;
     _preview = new WriteableBitmap(1, 1, 96, 96, PixelFormats.Bgra32, null);
     _preview.Clear();
     _preview.SetPixel(0, 0, 127, 0, 90, 255);
 }
开发者ID:ThomasWDonnelly,项目名称:Terraria-Map-Editor,代码行数:7,代码来源:BaseTool.cs

示例2: GeneratePreview

 public void GeneratePreview()
 {
     var bmp = new WriteableBitmap(_size.X, _size.Y, 96, 96, PixelFormats.Bgra32, null);
     var c = World.TileProperties[Tile].Color;
     bmp.Clear(Color.FromArgb(c.A, c.R, c.G, c.B));
     Preview = bmp;
     IsPreviewTexture = false;
 }
开发者ID:ThomasWDonnelly,项目名称:Terraria-Map-Editor,代码行数:8,代码来源:Sprite.cs

示例3: SelectionTool

        public SelectionTool(WorldViewModel worldViewModel)
        {
            _wvm = worldViewModel;
            _preview = new WriteableBitmap(1, 1, 96, 96, PixelFormats.Bgra32, null);
            _preview.Clear();
            _preview.SetPixel(0, 0, 127, 0, 90, 255);

            Icon = new BitmapImage(new Uri(@"pack://application:,,,/TEditXna;component/Images/Tools/shape_square.png"));
            Name = "Selection";
            IsActive = false;
        }
开发者ID:KeviinSkyline,项目名称:Terraria-Map-Editor,代码行数:11,代码来源:SelectionTool.cs

示例4: Button_Click

        /// <summary>
        /// Randomise the layout of points.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Create a new bitmap and set it as our canvas background.
            pBitmap = BitmapFactory.New((int)cnvPoints.ActualWidth, (int)cnvPoints.ActualHeight);
            var pBrush = new ImageBrush();
            pBrush.ImageSource = pBitmap;
            cnvPoints.Background = pBrush;

            // Clear the bitmap to light blue.
            using (pBitmap.GetBitmapContext())
                pBitmap.Clear(Colors.LightBlue);


            // Get the number we want to generate and update the UI.
            var iResult = 0;
            if (!int.TryParse(txtPoints.Text, out iResult))
            {
                txtPoints.Foreground = Brushes.Red;
                return;
            }
            if (iResult < 0)
            {
                txtPoints.Foreground = Brushes.Red;
                return;
            }
            txtPoints.Foreground = Brushes.Black;

            // Clear the tree and canvas.
            cnvPoints.Children.Clear();
            pTree = new KDTree.KDTree<EllipseWrapper>(2);

            // Create a list of points and draw a ghost ellipse for each one.
            using (pBitmap.GetBitmapContext())
            {
                // Generate X new random items.
                var pRandom = new Random();
                for (int i = 0; i < iResult; ++i)
                {
                    // Position it and add it to the canvas.
                    var x = pRandom.NextDouble() * cnvPoints.ActualWidth;
                    var y = pRandom.NextDouble() * cnvPoints.ActualHeight;

                    // Add it to the tree.
                    pTree.AddPoint(new double[] { x, y }, new EllipseWrapper(x, y));

                    // Draw a ghost visual for it.
                    //pBitmap.DrawEllipse((int)x - 2, (int)y - 2, (int)x + 2, (int)y + 2, Colors.Green);
                    pBitmap.DrawEllipse((int)x - 2, (int)y - 2, (int)x + 2, (int)y + 2, Colors.Orange);

                }
            }
        }
开发者ID:b3r3ch1t,项目名称:kd-sharp,代码行数:57,代码来源:MainWindow.xaml.cs

示例5: PreviewTool

        public override WriteableBitmap PreviewTool()
        {
            var bmp = new WriteableBitmap(_wvm.Brush.Width + 1, _wvm.Brush.Height + 1, 96, 96, PixelFormats.Bgra32, null);

            bmp.Clear();
            if (_wvm.Brush.Shape == BrushShape.Square)
                bmp.FillRectangle(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255));
            else
                bmp.FillEllipse(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255));

            _preview = bmp;
            return _preview;
        }
开发者ID:RandomSheep,项目名称:Terraria-Map-Editor,代码行数:13,代码来源:MorphTool.cs

示例6: MainPage

 public MainPage()
 {
    InitializeComponent();
    particleBmp = LoadBitmap("/WriteableBitmapExBlitSample;component/Data/FlowerBurst.jpg");
    circleBmp = LoadBitmap("/WriteableBitmapExBlitSample;component/Data/circle.png");
    particleSourceRect = new Rect(0, 0, 64, 64);
    bmp = new WriteableBitmap(640, 480);
    bmp.Clear(Colors.Black);
    image.Source = bmp;
    emitter = new ParticleEmitter();
    emitter.TargetBitmap = bmp;
    emitter.ParticleBitmap = particleBmp;
    CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
    this.MouseMove += new MouseEventHandler(MainPage_MouseMove);
 }
开发者ID:Narinyir,项目名称:WriteableBitmapEx,代码行数:15,代码来源:MainPage.xaml.cs

示例7: MainViewModel

        public MainViewModel()
        {
            SizeX = 768;
            SizeY = 512;
            SpotSizeX = 200;
            SpotSizeY = 233;

            SpotColors = new List<Color>
            {
                Color.FromArgb(150, 164, 232, 0),
                Color.FromArgb(150, 255, 185, 17),
                Color.FromArgb(150, 0, 149, 59),
                Color.FromArgb(150, 222, 184, 99),
                Color.FromArgb(150, 234, 0, 53),
            };

            var colors = new List<Color>
            {
                Colors.Red,
                Colors.Blue,
                Colors.Green
            };
            Overlay = new WriteableBitmap(SizeX, SizeY, 96, 96, PixelFormats.Pbgra32, new BitmapPalette(colors));
            Overlay.Clear(Colors.Black);

            PixSpots = new List<Blot>();
            Pixs = new List<byte[,]>();

            var spots =
                Directory.GetFiles(Directory.GetCurrentDirectory() + @"\img\").Where(p => p.Contains(".png")).ToArray();
            foreach (var spot in spots)
            {
                Pixs.Add(new byte[SpotSizeX, SpotSizeY]);
                var img = new WriteableBitmap(new BitmapImage(new Uri(spot)));
                for (var i = 0; i < img.PixelWidth; i++)
                    for (var j = 0; j < img.PixelHeight; j++)
                        if (img.GetPixel(i, j).A > 0)
                            Pixs[Pixs.Count - 1][i, j] = 1;
            }
        }
开发者ID:KonigLabs,项目名称:SpriteEvent,代码行数:40,代码来源:MainViewModel.cs

示例8: Draw

      public void Draw(WriteableBitmap writeableBmp)
      {
         if (writeableBmp != null)
         {
            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            using (writeableBmp.GetBitmapContext())
            {
               writeableBmp.Clear();
               Draw(writeableBmp, this.Root);
#if SILVERLIGHT
               writeableBmp.Invalidate();
#endif
            }
         }
      }
开发者ID:Narinyir,项目名称:WriteableBitmapEx,代码行数:15,代码来源:Plant.cs

示例9: MoveTool

        public override bool MoveTool(TileMouseEventArgs e)
        {
            WriteableBitmap bmp;

            if (_startPoint != null) _endPoint = e.Tile;
            CheckDirectionandDraw(e);
            ToolAnchorMode mode = ToolAnchorMode.Center;

            // Line draw preview
            if (_isRightDown && _startPoint != null && _endPoint != null) {
                var sp = (PointInt32)_startPoint;
                var ep = (PointInt32)_endPoint;
                var delta = ep - sp;
                var rect = new RectI(new PointInt32(), new SizeInt32(Math.Abs(delta.X) + 1, Math.Abs(delta.Y) + 1));

                // figure out exactly which PreviewMode
                mode = 0;
                if      (delta.X <  0) mode += (int)ToolAnchorModeParts.Left;
                else if (delta.X == 0) mode += (int)ToolAnchorModeParts.Center;
                else if (delta.X >  0) mode += (int)ToolAnchorModeParts.Right;

                if      (delta.Y <  0) mode += (int)ToolAnchorModeParts.Top;
                else if (delta.Y == 0) mode += (int)ToolAnchorModeParts.Middle;
                else if (delta.Y >  0) mode += (int)ToolAnchorModeParts.Bottom;

                // which direction to draw the line
                var linePnts = new PointInt32[2];
                switch (mode) {
                    case ToolAnchorMode.TopLeft:     linePnts = new[] { rect.BottomRight, rect.TopLeft }; break;
                    case ToolAnchorMode.TopRight:    linePnts = new[] { rect.BottomLeft, rect.TopRight }; break;
                    case ToolAnchorMode.BottomLeft:  linePnts = new[] { rect.TopRight, rect.BottomLeft }; break;
                    case ToolAnchorMode.BottomRight: linePnts = new[] { rect.TopLeft, rect.BottomRight }; break;
                    default:  // has middle or center, order doesn't matter
                        linePnts = new[] { rect.TopLeft, rect.BottomRight };
                        break;
                }

                bmp = new WriteableBitmap(
                    rect.W,
                    rect.H,
                    96,
                    96,
                    System.Windows.Media.PixelFormats.Bgra32,
                    null);

                bmp.Clear();
                foreach (PointInt32 p in WorldRenderer.DrawLine(linePnts[0], linePnts[1])) {
                    if (_selection.IsValid(p)) bmp.SetPixel(p.X, p.Y, previewColor);
                }
            }
            // Single dot
            else {
                bmp = new WriteableBitmap(
                    1,
                    1,
                    96,
                    96,
                    System.Windows.Media.PixelFormats.Bgra32,
                    null);

                bmp.Clear();
                bmp.SetPixel(0, 0, previewColor);
            }

            _properties.Image = bmp;
            _properties.PreviewMode = mode;

            return false;
        }
开发者ID:Dazmo,项目名称:Terraria-Map-Editor,代码行数:69,代码来源:Pencil.cs

示例10: GenereateMosaicPicture

        public static string GenereateMosaicPicture(IList<BitmapImage> images, string filename)
        {
            string key = string.Empty;

            try
            {
                // Generate avatar in bitmap.
                var bmp = new WriteableBitmap(PICTURE_DIMENSION, PICTURE_DIMENSION);
                bmp.Clear();
                int x = 0;
                int y = 0;

                int w = 0;
                int h = 0;
                if (images.Count == 1)
                {
                    w = PICTURE_DIMENSION;
                    h = PICTURE_DIMENSION;
                }
                else if (images.Count == 2)
                {
                    w = PART_DIMENSION;
                    h = PICTURE_DIMENSION;
                }
                else
                {
                    w = PART_DIMENSION;
                    h = PART_DIMENSION;
                }

                for (int i = 0; i < images.Count && i < 4; )
                {
                    if (images[i] == null)
                        continue;

                    var wb = new WriteableBitmap(images[i]);

                    if (wb.PixelHeight < h || wb.PixelWidth < w)
                    {
                        wb = wb.Resize(PICTURE_DIMENSION, PICTURE_DIMENSION, WriteableBitmapExtensions.Interpolation.Bilinear);
                    }

                    i++;

                    bmp.Blit(new Rect(x, y, w, h), wb,
                        new Rect(0, 0, w, h));

                    if (w == PART_DIMENSION)
                        x += w + 2; // Handle empty space between photos
                    else
                        x += w;

                    if (x >= PICTURE_DIMENSION)
                    {
                        x = 0;

                        if (h == PART_DIMENSION)
                            y += h + 2; // Handle empty space between photos
                        else
                            y += h;
                    }

                    if (y >= PICTURE_DIMENSION)
                        break;
                }

                if (_SaveJpeg(bmp, filename))
                    key = filename;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GenereateMosaicPicture failed." + ex.Message);
            }

            return key;
        }
开发者ID:optiklab,项目名称:VKMessanger,代码行数:76,代码来源:MosaicPictureGenerator.cs

示例11: PreviewTool

        public override WriteableBitmap PreviewTool()
        {
            var bmp = new WriteableBitmap(
                1,
                1,
                96,
                96,
                PixelFormats.Bgra32,
                null);

            bmp.Clear();
            bmp.SetPixel(0, 0, 127, 0, 90, 255);
            return bmp;
        }
开发者ID:Kyphis,项目名称:Terraria-Map-Editor,代码行数:14,代码来源:Pencil.cs

示例12: ImageGrid_SizeChanged

        private void ImageGrid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Wb = new WriteableBitmap((int)e.NewSize.Width, (int)e.NewSize.Height, 96, 96, PixelFormats.Bgra32, null);
            MyImage.Source = Wb;

            Wb.Clear(BackgroundColor);
        }
开发者ID:gczarnocki,项目名称:raster-paint,代码行数:7,代码来源:ClipWindow.xaml.cs

示例13: FullScreen

 private void FullScreen()
 {
     var writeableBitmap = new WriteableBitmap(width,height);
     writeableBitmap.Clear(Colors.Black);
     OpacityMask = writeableBitmap;
 }
开发者ID:KnownSubset,项目名称:Rephoto,代码行数:6,代码来源:CameraViewModel.cs

示例14: PreviewTool

        public override WriteableBitmap PreviewTool()
        {
            var c = Color.FromArgb(127, 0, 90, 255);
            var w = _properties.Width;
            var h = _properties.Height;
            var bmp = new WriteableBitmap(
                w,
                w,
                96,
                96,
                System.Windows.Media.PixelFormats.Bgra32,
                null);

            bmp.Clear();
            if (_properties.BrushShape == ToolBrushShape.Square)
                 bmp.FillRectangle(0, 0, w, h, c);
            else bmp.FillEllipse  (0, 0, w, h, c);
            return bmp;
        }
开发者ID:Dazmo,项目名称:Terraria-Map-Editor,代码行数:19,代码来源:Brush.cs

示例15: Generate

        public WriteableBitmap Generate(String content, Encoding encoding)
        {
            bool[][] matrix = CalQrcode(encoding.GetBytes(content));
            WriteableBitmap image = new WriteableBitmap((matrix.Length * QRCodeScale), (matrix.Length * QRCodeScale));
            image.Clear(QRCodeBackgroundColor);

            var color = QRCodeForegroundColor;
            var a = color.A + 1;
            var col = (color.A << 24)
               | ((byte)((color.R * a) >> 8) << 16)
               | ((byte)((color.G * a) >> 8) << 8)
               | ((byte)((color.B * a) >> 8));


            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix.Length; j++)
                {
                    if (matrix[j][i])
                    {
                        image.FillRectangle(j * QRCodeScale, i * QRCodeScale, (j + 1) * QRCodeScale, (i + 1) * QRCodeScale, col);
                    }
                }
            }
            return image;
        }
开发者ID:rcrozon,项目名称:PartyProject,代码行数:26,代码来源:QRCodeEncoder.cs


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