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);
 }
Ejemplo n.º 2
0
 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;
 }
        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;
        }
Ejemplo n.º 4
0
        /// <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);

                }
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
 private void FullScreen()
 {
     var writeableBitmap = new WriteableBitmap(width,height);
     writeableBitmap.Clear(Colors.Black);
     OpacityMask = writeableBitmap;
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
      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
            }
         }
      }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
      private void DetectMarkers(WriteableBitmap bmp)
      {
         // Init. here because the captureSource.VideoCaptureDevice.DesiredFormat getter is not reliable and throws an Exception
         if (arDetector == null)
         {
            InitializeDetector(bmp.PixelWidth, bmp.PixelHeight);
         }

         // Detect
         var detectedResults = arDetector.DetectAllMarkers(bmp);

         // Reused for marker highlighting
         bmp.Clear();
         ViewportOverlay.Source = bmp;

         if (detectedResults.HasResults)
         {
            var trans = detectedResults[0].Transformation.ToBalderMatrix();

            if (detectedResults.Count > 1)
            {
               // Calculate distance vector
               wayInterpol += (3f * sign);
               var trans2 = detectedResults[1].Transformation.ToBalderMatrix();
               var p1 = new Vector(trans[3, 0], trans[3, 1], trans[3, 2]);
               var p2 = new Vector(trans2[3, 0], trans2[3, 1], trans2[3, 2]);
               var d = p1 - p2;
               var dn = Vector.Normalize(d);
               var p = dn * -wayInterpol;

               // Turning point ?
               if (p.LengthSquared() > d.LengthSquared())
               {
                  sign = -1;
               }
               else if (wayInterpol < 0)
               {
                  sign = 1;
               }
               var translate = Matrix.CreateTranslation(p);

               // Calculate Yaw and align the mesh to it
               var dot = Vector.Dot(Vector.UnitY, dn);
               var rotRad = Math.Acos(dot);
               var rotDeg = MathHelper.ToDegrees((float)rotRad);
               var yaw = Matrix.CreateRotationZ(150 + rotDeg + (sign > 0 ? 0 : 180));

               // Combine matrix
               trans = yaw * trans * translate;
            }
            else
            {
               // If no 2nd marker was found only rotate around z axis
               timedRotation += 2;
               trans = Matrix.CreateRotationZ(timedRotation) * trans;
            }
            // Transform the mesh and change coordinate system
            ApplyFinalTransformation(trans);

            // Highlight detected markers using the  WriteableBitmapEx
            foreach (var r in detectedResults)
            {
               bmp.DrawQuad((int)r.Square.P1.X, (int)r.Square.P1.Y,
                              (int)r.Square.P2.X, (int)r.Square.P2.Y,
                              (int)r.Square.P3.X, (int)r.Square.P3.Y,
                              (int)r.Square.P4.X, (int)r.Square.P4.Y, Colors.Red);
            }
         }
      }
Ejemplo n.º 13
0
        public override WriteableBitmap PreviewTool()
        {
            var bmp = new WriteableBitmap(
                1,
                1,
                96,
                96,
                System.Windows.Media.PixelFormats.Bgra32,
                null);

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

            return bmp;
        }
Ejemplo n.º 14
0
      private void DetectMarkers(WriteableBitmap bmp)
      {
         // Init. here because the captureSource.VideoCaptureDevice.DesiredFormat getter is not reliable and throws an Exception
         if (!isInit)
         {
            InitializeDetector(bmp.PixelWidth, bmp.PixelHeight);
            isInit = true;
         }

         // Detect
         var dr = arDetector.DetectAllMarkers(bmp);

         // Reused for marker highlighting
         bmp.Clear();
         ViewportOverlay.Source = bmp;

         if (dr.HasResults)
         {
            // Set camera
            camera.ProjectionTransform = arDetector.Projection.ToXnaMatrix();

            // Transform Sun
            var sunResult = dr.FirstOrDefault(d => d.Marker == lMarker);
            if (sunResult != null && sunResult.Confidence > MinConfidence)
            {
               Transform(Sun, sunResult.Transformation, TxtSun);
            }
            else
            {
               TxtSun.Visibility = Visibility.Collapsed;
               Sun.IsVisible = false;
            }

            // Transform Earth
            var earthResult = dr.FirstOrDefault(d => d.Marker == slarMarker);
            if (sunResult == null && earthResult == null)
            {
               earthResult = dr[0];
            }
            if (earthResult != null && earthResult.Confidence > MinConfidence)
            {
               Transform(Earth, earthResult.Transformation, TxtEarth);
            }
            else
            {
               TxtEarth.Visibility = Visibility.Collapsed;
               Earth.IsVisible = false;
            }

            //// Highlight detected markers
            //var txt = String.Empty;
            //foreach (var r in dr)
            //{
            //   bmp.DrawQuad((int)r.Square.P1.X, (int)r.Square.P1.Y, (int)r.Square.P2.X, (int)r.Square.P2.Y, (int)r.Square.P3.X, (int)r.Square.P3.Y, (int)r.Square.P4.X, (int)r.Square.P4.Y, Colors.Red);
            //   txt += String.Format("{0}.Confidence = {1:0.00}   ", r.Marker.Name, r.Confidence);
            //}
            //Txt.Text = txt;
         }
      }
Ejemplo n.º 15
0
        private void editPic()
        {
            #region textblocks
            TextBlock bigCap = new TextBlock();
            TextBlock smallCap = new TextBlock();
            bigCap.Text = topLineTextBox.Text.ToUpper();
            smallCap.Text = bottomLineTextBox.Text;

            bigCap.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            bigCap.TextAlignment = TextAlignment.Center;
            bigCap.Width = posterWidth;

            smallCap.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            smallCap.TextAlignment = TextAlignment.Center;
            smallCap.Width = posterWidth;

            bigCap.FontFamily = new FontFamily("Times New Roman");
            smallCap.FontFamily = new FontFamily("Times New Roman");
            bigCap.FontSize = 46;
            smallCap.FontSize = 20;
            bigCap.FontWeight = FontWeights.Bold;
            bigCap.TextWrapping = TextWrapping.Wrap;
            smallCap.TextWrapping = TextWrapping.Wrap;
            bigCap.Foreground = new SolidColorBrush(Colors.White);
            smallCap.Foreground = new SolidColorBrush(Colors.White);

            #endregion

            Image posterImage = new Image();
            posterImage.Source = posterBitmap;
            posterImage.Height = imgHeight;
            posterImage.Width = imgWidth;
            posterImage.Stretch = Stretch.UniformToFill;

            Border b = new Border();
            b.BorderThickness = new Thickness(5);
            b.BorderBrush = new SolidColorBrush(Colors.White);
            b.Child = null;
            b.Child = posterImage;

            Rectangle rec = new Rectangle();
            rec.Width = imgWidth + 6;
            rec.Height = imgHeight + 6;
            rec.Fill = new SolidColorBrush(Colors.White);

            WriteableBitmap newBitmap = new WriteableBitmap(posterWidth, posterHeight);
            newBitmap.Clear(Colors.Black);

            newBitmap.Render(rec, new TranslateTransform() { Y = topMargin - 3, X = ((posterWidth - imgWidth) / 2)-3 });
            newBitmap.Render(b, new TranslateTransform() { Y = topMargin, X = (posterWidth - imgWidth) / 2 });
            newBitmap.Render(bigCap, new TranslateTransform() {Y = topMargin+imgHeight+20, X = 0});
            newBitmap.Render(smallCap, new TranslateTransform() { Y = topMargin + imgHeight+ 80, X = 0 });
            newBitmap.Invalidate();
            savePicture(newBitmap);
        }
Ejemplo n.º 16
0
        public void Start()
        {
            Win = false;
            Lost = false;
            Arena = BitmapFactory.New(300, 300);
            Arena.Clear(Colors.Black);

            Random rand = new Random();
            if (Network.isServer())
            {
                MyColor = Colors.Lime;
                OpponentColor = Colors.Yellow;
                Position = firstPlayerCoord;
                OpponentPosition = secondPlayerCoord;
                Facing = model.Facing.Down;
                OpponentFacing = model.Facing.Up;
             }
             else
             {
                MyColor = Colors.Yellow;
                OpponentColor = Colors.Lime;
                Position = secondPlayerCoord;
                OpponentPosition = firstPlayerCoord;
                Facing = model.Facing.Up;
                OpponentFacing = model.Facing.Down;
              }
              GameStart();
        }
Ejemplo n.º 17
0
      private void DetectMarkers(WriteableBitmap bmp)
      {
         // Init. here because the captureSource.VideoCaptureDevice.DesiredFormat getter is not reliable and throws an Exception
         if (!isInit)
         {
            // Init AR
            arDetector.Initialize(bmp.PixelWidth, bmp.PixelHeight, Game.Camera.Near, Game.Camera.Far, new List<Marker> {slarMarker});
            isInit = true;
         }

         // Detect
         var dr = arDetector.DetectAllMarkers(bmp);

         // Reused for marker highlighting
         bmp.Clear();
         ViewportOverlay.Source = bmp;

         if (dr.HasResults)
         {
            var transformation = Balder.Math.Matrix.CreateTranslation(0, -5, 0) * Balder.Math.Matrix.CreateRotationX(90) * dr[0].Transformation.ToBalder();
            Game.SetWorldMatrix(transformation);

            // Highlight detected markers
            var txt = String.Empty;
            foreach (var r in dr)
            {
               bmp.DrawQuad((int)r.Square.P1.X, (int)r.Square.P1.Y, (int)r.Square.P2.X, (int)r.Square.P2.Y, (int)r.Square.P3.X, (int)r.Square.P3.Y, (int)r.Square.P4.X, (int)r.Square.P4.Y, Colors.Red);
               txt += String.Format("{0}.Confidence = {1:0.00}   ", r.Marker.Name, r.Confidence);
            }
         }
      }
Ejemplo n.º 18
0
        // a new person arrived to the chat room , lets do lots of things... update de chat, send a notify, lets see if he is already on our list of friends
        void _model_NewPersonArrive(object sender, Models.Events.NewPersonEventArgs e)
        {
            if (e.Error == null)
            {

                //it's our new person message
                if (this.User.Id == e.Result.Id)
                {

                }
                else
                {

                    //  _friends.Contains(e.Result) dosent't work don't know why

                    Person friend = GetFriendAsPerson(e.Result.Id);

                    if (friend != null)
                    {
                        //this friends already exists

                    }
                    else
                    {

                        WriteableBitmap tb = new WriteableBitmap(60, 60);
                        tb.Clear(Colors.Orange);

                        e.Result.Video = tb;
                        _friends.Add(e.Result);
                        _messages.Add(new ChatMessage { User = e.Result, Msg = " : Joins the chat", MessageDateTime= DateTime.Now });

                        _model.SendUsername();
                    }

                }
            }
        }
Ejemplo n.º 19
0
        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;
        }
Ejemplo n.º 20
0
        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;
        }
Ejemplo n.º 21
0
        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;
        }
Ejemplo n.º 22
-1
        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;
            }
        }