private void CreateDragVisual()
        {
            ClearDragVisual();

            var bitmap = new System.Windows.Media.Imaging.WriteableBitmap(this, null);
            bitmap.Render(this, null);
            bitmap.Invalidate();

            _dragVisual = new System.Windows.Controls.Image();
            _dragVisual.Source = bitmap;

            // find topmost canvas.. (so we can add the drag visual as a child
            // and ensure that it is on top of everything)
            //
            var canvas = this.GetTopmostParentOfType<Canvas>();

            canvas.Children.Add(_dragVisual);

            var point = this.GetRelativePosition(canvas);

            _dragVisual.SetValue(Canvas.TopProperty, point.Y);
            _dragVisual.SetValue(Canvas.LeftProperty, point.X);

            // Really make sure the drag visual is on top
            //
            Canvas.SetZIndex(_dragVisual, Int16.MaxValue);
        }
Example #2
0
        public static Canvas DrawImagePhoto(string checkVal, double orgX, double orgY)
        {
            Canvas canvas = new Canvas();

            Canvas.SetLeft(canvas, orgX - 10);
            Canvas.SetTop(canvas, orgY - 10);

            if (!string.IsNullOrEmpty(checkVal) && File.Exists(checkVal))
            {
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.CacheOption = BitmapCacheOption.OnLoad;

                using (Stream ms = new MemoryStream(File.ReadAllBytes(checkVal)))
                {
                    bi.StreamSource = ms;
                    bi.EndInit();
                    bi.Freeze();
                }

                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Source = bi;
                image.Width  = 105;                       //设置图片宽度
                image.Height = 111;                       //设置图片高度
                image.SetValue(Canvas.LeftProperty, 1.0); //设置图片x坐标
                image.SetValue(Canvas.TopProperty, 1.0);  //设置图片y坐标
                canvas.Children.Add(image);
            }

            return(canvas);
        }
Example #3
0
        private void Canvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // If we're not dragging, don't bother
            if (!_isDragging)
            {
                return;
            }

            FrameworkElement element = sender as FrameworkElement;

            if (element == null)
            {
                return;
            }

            // Get the position of the mouse relative to the canvas
            WindowsPoint mousePoint = e.GetPosition(CnvMain);

            // Offset the mouse position by the original offset position
            mousePoint.Offset(-_offset.X, -_offset.Y);

            // Move the element on the canvas
            _draggedImage.SetValue(Canvas.LeftProperty, mousePoint.X);
            _draggedImage.SetValue(Canvas.TopProperty, mousePoint.Y);
        }
Example #4
0
        public void DrawBitmap(Bitmap bit, int x, int y)
        {
            System.Windows.Controls.Image im = new System.Windows.Controls.Image();
            IntPtr       intPt = bit.GetHbitmap();
            BitmapSource bs    = Imaging.CreateBitmapSourceFromHBitmap(intPt, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            im.Source = bs;
            canvasField.Children.Add(im);

            im.SetValue(Canvas.TopProperty, Convert.ToDouble(y));
            im.SetValue(Canvas.LeftProperty, Convert.ToDouble(x));

            DeleteObject(intPt);
        }
 public static void paint_thmb_scr(GlobalTypes.ClientInfo item)
 {
     XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate
     {
         lock (MainWindow.Client_Catalog)
         {
             System.Windows.Controls.Image tmp = new System.Windows.Controls.Image();
             tmp.MouseLeftButtonUp            += unicast;
             tmp.Stretch             = Stretch.Fill;
             tmp.Margin              = new Thickness(12, 15, 12, 0);
             tmp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
             tmp.Width  = 170;
             tmp.Height = 100;
             item.Image = tmp;
             DockPanel pic_container = new DockPanel();
             TextBlock name          = new TextBlock();
             name.FontSize           = 12;
             name.FontFamily         = new System.Windows.Media.FontFamily("Arial");
             name.MaxWidth           = 170;
             name.TextTrimming       = TextTrimming.CharacterEllipsis;
             name.Text = item.HostInfo.HostName;
             name.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
             pic_container.Children.Add(tmp);
             pic_container.Children.Add(name);
             name.Foreground = System.Windows.Media.Brushes.White;
             tmp.SetValue(DockPanel.DockProperty, Dock.Top);
             name.SetValue(DockPanel.DockProperty, Dock.Bottom);
             tmp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
             XPorter.Bus.Main_Handle.Scr_Cont.Children.Add(pic_container);
             //В другой модуль Create context menu
             System.Windows.Controls.ContextMenu menu = ReinCorpDesign.sources.UserContextMenu.get_contx_menu(item);
             item.Image.ContextMenu = menu;
         }
     }));
 }
Example #6
0
        public void AddRiverCard(int player, int number, MahjongCard card, Grid container)
        {
            // Create a new card
            System.Windows.Controls.Image imgCard = new System.Windows.Controls.Image()
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Height  = 40,
                Width   = 24,
                Stretch = Stretch.Uniform,
            };

            // Set the render to high quality
            imgCard.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);

            // Set card position
            imgCard.Margin = new Thickness(number % 7 * imgCard.Width, number / 7 * imgCard.Height, 0, 0);

            // Set image
            imgCard.Source = cardImage[card.name];

            // Set tag
            HandCardInfo handCardInfo = new HandCardInfo()
            {
                card   = card,
                player = player,
            };

            imgCard.Tag = handCardInfo;

            // Add the card
            container.Children.Add(imgCard);
        }
Example #7
0
        private void AddFuruCard(int number, MahjongCardFuru furu, Grid container, int height = 40, int width = 24)
        {
            int i = 0;

            foreach (MahjongCard card in furu.cards)
            {
                // Create a new card
                System.Windows.Controls.Image imgCard = new System.Windows.Controls.Image()
                {
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Height  = height,
                    Width   = width,
                    Stretch = Stretch.Uniform,
                };

                // Set the render to high quality
                imgCard.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);

                // Set card position
                imgCard.Margin = new Thickness(i * imgCard.Width, number * imgCard.Height, 0, 0);

                // Set image
                imgCard.Source = cardImage[card.name];

                // Add the card
                container.Children.Add(imgCard);

                i++;
            }
        }
Example #8
0
        public override void SetupCustomUIElements(object ui)
        {
            var nodeUI = ui as dynNodeView;

            image1 = new System.Windows.Controls.Image
            {
                MaxWidth            = 400,
                MaxHeight           = 400,
                Margin              = new Thickness(5),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                Name = "image1",
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };

            nodeUI.grid.Children.Add(image1);
            image1.SetValue(Grid.RowProperty, 2);
            image1.SetValue(Grid.ColumnProperty, 0);
            image1.SetValue(Grid.ColumnSpanProperty, 3);
        }
Example #9
0
        public override void SetupCustomUIElements(Controls.dynNodeView nodeUI)
        {
            image1 = new System.Windows.Controls.Image
            {
                //Width = 320,
                //Height = 240,
                MaxWidth            = 400,
                MaxHeight           = 400,
                Margin              = new Thickness(5),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                Name = "image1",
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };

            //nodeUI.inputGrid.Children.Add(image1);
            nodeUI.grid.Children.Add(image1);
            image1.SetValue(Grid.RowProperty, 2);
            image1.SetValue(Grid.ColumnProperty, 0);
            image1.SetValue(Grid.ColumnSpanProperty, 3);
        }
        private Image GenerateTabImage(int index, string name)
        {
            Image imgTab = new Image();

            imgTab.SetValue(Grid.ColumnProperty, Tabs.Count);
            imgTab.Source = bmpTab;
            imgTab.HorizontalAlignment = HorizontalAlignment.Stretch;
            imgTab.VerticalAlignment   = VerticalAlignment.Stretch;
            imgTab.MouseDown          += tab_MouseDown;
            imgTab.Name = $"img{index}{name}";

            return(imgTab);
        }
Example #11
0
        public void OnArenaChange(object sender, EventArgs args)
        {
            BoardGrid.Children.Clear();

            DisplayBoard();

            DisplayBots();

            DisplayBombs();

            DisplayMissiles();

            DisplayExplosions();

            PlayersGrid.Children.Clear();

            PlayersGrid.ColumnDefinitions.Clear();

            for (int i = 0; i < _arena.Bots.Count; i++)
            {
                PlayersGrid.ColumnDefinitions.Add(new ColumnDefinition());

                var botGrid = new Grid();
                botGrid.SetValue(Grid.ColumnProperty, i);

                var text = new TextBlock()
                {
                    Text     = _arena.Bots[i].Name,
                    Margin   = new Thickness(1, 0, 0, 0),
                    FontSize = PlayersGrid.Height * 0.75
                };
                text.SetValue(Grid.ColumnProperty, 1);

                var image = new Image()
                {
                    Source = _arena.Bots[i].Image
                };
                image.SetValue(Grid.ColumnProperty, 0);

                botGrid.Children.Add(image);
                botGrid.Children.Add(text);

                PlayersGrid.Children.Add(botGrid);
            }
        }
Example #12
0
        private void AddHandCard(int player, int number, MahjongCard card, Grid container, int height = 75, int width = 46)
        {
            // Create a new card
            System.Windows.Controls.Image imgCard = new System.Windows.Controls.Image()
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Height  = height,
                Width   = width,
                Stretch = Stretch.Uniform,
            };

            // Set the render to high quality
            imgCard.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);

            // Set card position
            imgCard.Margin = new Thickness((number * imgCard.Width) + 5, 10, 0, 0);

            // Set image
            imgCard.Source = cardImage[card.name];

            // Set mouse event
            imgCard.MouseEnter += HandCard_MouseEnter;
            imgCard.MouseLeave += HandCard_MouseLeave;

            // Set click event
            imgCard.MouseLeftButtonUp += HandCard_MouseLeftButtonUp;

            // Set tag
            HandCardInfo handCardInfo = new HandCardInfo()
            {
                card   = card,
                player = player,
            };

            imgCard.Tag = handCardInfo;

            // Add the card
            container.Children.Add(imgCard);
        }
Example #13
0
        private void AddCard(int item, int number, MahjongCard card, Grid container, int height = 75, int width = 46, int interval = 5)
        {
            // Create a new card
            System.Windows.Controls.Image imgCard = new System.Windows.Controls.Image()
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Height  = height,
                Width   = width,
                Stretch = Stretch.Uniform,
            };

            // Set the render to high quality
            imgCard.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);

            // Set card position
            imgCard.Margin = new Thickness(number * (imgCard.Width + interval), item * (imgCard.Height + interval), 0, 0);

            // Set image
            imgCard.Source = cardImage[card.name];

            // Add the card
            container.Children.Add(imgCard);
        }
Example #14
0
 internal static void SetErrorDetected(Image obj, bool value)
 {
     obj.SetValue(ErrorDetectedProperty, value);
 }
Example #15
0
 public static void SetSourceType(Image obj, SourceType value)
 {
     obj.SetValue(SourceTypeProperty, value);
 }
Example #16
0
 public static void SetSource(Image obj, object value)
 {
     obj.SetValue(SourceProperty, value);
 }
Example #17
0
 public static void SetDisplayWaitingAnimationDuringLoading(Image obj, bool value)
 {
     obj.SetValue(DisplayWaitingAnimationDuringLoadingProperty, value);
 }
Example #18
0
 public static void SetDisplayOption(Image obj, DisplayOptions value)
 {
     obj.SetValue(DisplayOptionProperty, value);
 }
Example #19
0
        private Image makeApple(int numSides, int skip, double size, double spin, Point center, Brush brush,
            Brush brushStroke, double strokeThickness, double opacity)
        {
            System.Windows.Controls.Image apple = new System.Windows.Controls.Image();
            apple.Source = this.toBitmapImage(ShoopDoup.Properties.Resources.apple);
            apple.SetValue(Canvas.LeftProperty, center.X);
            apple.SetValue(Canvas.TopProperty, center.Y);
            apple.Height = 150;
            apples.Add(apple);

            return apple;
        }
 private void PrepareImages()
 {
     if (DesignerProperties.IsInDesignTool)
     {
         if (Film != null)
             Film.Children.Clear();
         offsetTop = 0;
         for (int i = 1; i <= 200; i++)
         {
             imgNext = new System.Windows.Controls.Image();
             imgNext.Source = new BitmapImage(new Uri("/Images/Effects/" + ImagesFolder + "/" + i + "." + ImageFilesExtension, UriKind.RelativeOrAbsolute));
             imgNext.SetValue(Canvas.TopProperty, imageHeight * offsetTop++);
             if (Film != null)
                 Film.Children.Add(imgNext);
         }
         if (Film != null)
             Film.SetValue(Canvas.TopProperty, Math.Floor(CurrentImageNum - 1) * -imageHeight);
     }
 }
Example #21
0
        private void loadImageAs(string path, System.Windows.Controls.Image elem)
        {
            ImageSourceConverter imgs = new ImageSourceConverter();

            elem.SetValue(Image.SourceProperty, imgs.ConvertFromString(path));
        }
Example #22
0
        void _fpScanner_OnFingerprintsDetected(List <Fingerprint> fingerprints)
        {
            //ResetGUI();
            //StopCapturing();


            #region GUI - Display Fingerprints
            xamlStackPanelFingerprints.Children.Clear();
            int imageWidth = (int)xamlStackPanelFingerprints.RenderSize.Width / fingerprints.Count;
            foreach (Fingerprint fingerprint in fingerprints)
            {
                System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                Bitmap bmp = new Bitmap(fingerprint.Image);
                img.Source = Utils.BitmapToBitmapSource(bmp);

                TextBlock tbNFIQ = new TextBlock();
                tbNFIQ.Text              = "NFIQ2: " + fingerprint.NFIQ2;
                tbNFIQ.FontSize          = 80;
                tbNFIQ.TextAlignment     = TextAlignment.Center;
                tbNFIQ.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
                tbNFIQ.Foreground        = Utils.GetBrushFromNFIQ2(fingerprint.NFIQ2);

                Grid          grid     = new Grid();
                RowDefinition gridRow1 = new RowDefinition();
                gridRow1.Height = new GridLength(1, GridUnitType.Star);
                RowDefinition gridRow2 = new RowDefinition();
                gridRow2.Height = new GridLength(1, GridUnitType.Star);
                grid.RowDefinitions.Add(gridRow1);
                grid.RowDefinitions.Add(gridRow2);

                img.SetValue(Grid.RowProperty, 0);
                tbNFIQ.SetValue(Grid.RowProperty, 1);

                grid.Children.Add(img);
                grid.Children.Add(tbNFIQ);

                grid.Margin = new Thickness(30, 0, 30, 0);

                xamlStackPanelFingerprints.Children.Add(grid);
            }
            #endregion

            //if (_selectedUser != null)
            //{
            try
            {
                //ResetGUI();
                //StartCapturing();
                //DisplayMessage("hola");

                //Verify User
                DisplayMessage("Verificando huellas");
                //AFISVerificationResult result = _afis.VerifyUser(_selectedUser.ID, fingerprints, Properties.Settings.Default.VerificationThreshold);
                AFISVerificationResult result = _afis.muserpol_verifyUser(0, fingerprints, Properties.Settings.Default.VerificationThreshold, this);
                String scoreString            = String.Format("{0:0.00}", result.Score);



                //MessageBox.Show("hola como estan ");



                if (result.Hit)
                {
                    displayMessage(String.Format("AFILIADO VERIFICADO ({0})", scoreString), Utils.COLOR_DERMALOG_GREEN);
                }
                else
                {
                    if (result.Score < 0)
                    {
                        displayMessage(String.Format("AFILIADO NO BIOMETRIZADO ({0})", scoreString), Utils.COLOR_DERMALOG_BLUE);
                    }
                    else
                    {
                        displayMessage(String.Format("AFILIADO NO VERIFICADO ({0})", scoreString), Utils.COLOR_DERMALOG_RED);
                    }
                }
            }
            catch (Exception e)
            {
                DisplayError(e.Message);
            }
            //}

            //dispose allocated fingerprint templates
            foreach (Fingerprint fingerprint in fingerprints)
            {
                fingerprint.Dispose();
            }

            _fpScanner.Freeze(false);
        }
Example #23
0
        /// <summary>
        /// Load bitmap image from resource
        /// </summary>
        /// <param name="pathInApplication">Path image in application</param>
        /// <param name="assembly">Assemply has this image</param>
        /// <returns>Bitmap image/Image source</returns>
        //public static BitmapImage LoadBitmapFromResource(string pathInApplication, Assembly assembly = null)
        //{
        //    if (assembly == null)
        //    {
        //        assembly = Assembly.GetCallingAssembly();
        //    }

        //    if (pathInApplication[0] == '/')
        //    {
        //        pathInApplication = pathInApplication.Substring(1);
        //    }

        //    return new BitmapImage(new Uri(@"pack://application:,,,/" + assembly.GetName().Name + ";component/" + pathInApplication, UriKind.Absolute));
        //}

        /// <summary>
        /// Set image (not checked)
        /// </summary>
        /// <param name="image"></param>
        /// <param name="imageSource"></param>
        public static void SetImage(System.Windows.Controls.Image image, string imageSource)
        {
            image.SetValue(System.Windows.Controls.Image.SourceProperty, new ImageSourceConverter().ConvertFromString(imageSource));
        }
        public void OnArenaChange(object sender, EventArgs args)
        {
            BoardGrid.Children.Clear();

            DisplayBoard();

            DisplayBots();

            DisplayBombs();

            DisplayMissiles();

            DisplayExplosions();

            PlayersGrid.Children.Clear();

            PlayersGrid.ColumnDefinitions.Clear();

            for (int i = 0; i < _arena.Bots.Count; i++)
            {
                PlayersGrid.ColumnDefinitions.Add(new ColumnDefinition());

                var botGrid = new Grid();
                botGrid.SetValue(Grid.ColumnProperty, i);

                var text = new TextBlock()
                {
                    Text = _arena.Bots[i].Name,
                    Margin = new Thickness(1, 0, 0, 0),
                    FontSize = PlayersGrid.Height * 0.75
                };
                text.SetValue(Grid.ColumnProperty, 1);

                var image = new Image()
                {
                    Source = _arena.Bots[i].Image
                };
                image.SetValue(Grid.ColumnProperty, 0);

                botGrid.Children.Add(image);
                botGrid.Children.Add(text);

                PlayersGrid.Children.Add(botGrid);
            }
        }
Example #25
0
 public static void SetSetSource(SWC.Image target, byte[] value)
 {
     target.SetValue(SetSourceProperty, value);
 }
Example #26
0
 internal static void SetIsLoading(Image obj, bool value)
 {
     obj.SetValue(IsLoadingProperty, value);
 }
 public void putImageData(object imagedata, double dx, double dy)
 {
     if (double.IsNaN(dx) || double.IsInfinity(dx) || double.IsInfinity(dy) || double.IsNaN(dy))
     {
         throw new NotSupportedException(NOT_SUPPORTED_ERR);
     }
     if (!(imagedata is ImageData))
     {
         throw new Exception(TYPE_MISTMATCH_ERR);
     }
     var img = imagedata as ImageData;
     // We are using 32 bit color.
     int bytesPerPixel = 4;
     // Where we are going to store our pixel information.
     var pixels = new byte[img.height * img.width * bytesPerPixel];
     byte[] data = Utils.ConvertJSArrayToByteArray(img.data);
     for (int y = 0; y < img.height; y++)
     {
         for (int x = 0; x < img.width; x++)
         {
             int index = y * (int)img.width * 4 + x * 4;
             pixels[index] = data[index];
             pixels[index + 1] = data[index + 1];
             pixels[index + 2] = data[index + 2];
             pixels[index + 3] = data[index + 3];
         }
     }
     // Where we are going to store our pixel information.
     // Calculate the stride of the bitmap
     int stride = (int)img.width * bytesPerPixel;
     BitmapSource source = BitmapSource.Create((int)img.width, (int)img.height, 96, 96, PixelFormats.Pbgra32,
                                               null,
                                               pixels, stride);
     source.Freeze();
     var image = new Image();
     image.Source = source;
     image.SetValue(System.Windows.Controls.Canvas.TopProperty, dy);
     image.SetValue(System.Windows.Controls.Canvas.LeftProperty, dx);
     _surface.Children.Add(image);
 }
        public void drawImage(object pImg, double dx, double dy, double dw, double dh)
        {
            if (pImg is ImageData)
            {
                var imageData = ((ImageData)pImg);
                string url = imageData.src;

                var image = new Image();
                var imageSource = new BitmapImage();
                if (_httpRegex.IsMatch(url))
                {
                    var client = new WebClient();
                    byte[] bytes = client.DownloadData(url);
                    using (var memoryStream = new MemoryStream(bytes))
                    {
                        imageSource.BeginInit();
                        imageSource.StreamSource = memoryStream;
                        imageSource.EndInit();
                    }
                }
                else
                {
                    imageSource = new BitmapImage();
                    imageSource.BeginInit();
                    imageSource.CacheOption = BitmapCacheOption.OnLoad;
                    imageSource.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    imageSource.UriSource = new Uri(url, UriKind.RelativeOrAbsolute);
                    imageSource.EndInit();
                }
                image.Source = imageSource;
                image.SetValue(System.Windows.Controls.Canvas.TopProperty, dy);
                image.SetValue(System.Windows.Controls.Canvas.LeftProperty, dx);
                if (dw > 0 && dh > 0)
                {
                    image.Width = dw;
                    image.Height = dh;
                }
                _surface.Children.Add(image);
                imageData.width = (uint)image.Width;
                imageData.height = (uint)image.Height;
            }
            if (OnPartialDraw != null)
            {
                OnPartialDraw();
            }
        }
        public void putImageData(object imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth,
                                 double dirtyHeight)
        {
            if (double.IsNaN(dx) || double.IsInfinity(dx) || double.IsInfinity(dy) || double.IsNaN(dy)
                || double.IsInfinity(dirtyX) || double.IsNaN(dirtyX) || double.IsInfinity(dirtyY) ||
                double.IsNaN(dirtyY)
                || double.IsInfinity(dirtyWidth) || double.IsNaN(dirtyWidth) || double.IsInfinity(dirtyHeight) ||
                double.IsNaN(dirtyHeight))
            {
                throw new NotSupportedException(NOT_SUPPORTED_ERR);
            }
            if (!(imagedata is ImageData))
            {
                throw new Exception(TYPE_MISTMATCH_ERR);
            }
            var img = imagedata as ImageData;
            if (dirtyWidth < 0)
            {
                dirtyWidth += dirtyX;
            }
            if (dirtyHeight < 0)
            {
                dirtyHeight += dirtyY;
            }
            if (dirtyX < 0)
                dirtyX = 0;
            if (dirtyY < 0)
                dirtyY = 0;
            if (dirtyWidth + dirtyX > img.width)
            {
                dirtyWidth = img.width - dirtyX;
            }
            if (dirtyHeight + dirtyY > img.height)
            {
                dirtyHeight = img.height - dirtyY;
            }
            if (dirtyHeight <= 0 || dirtyWidth <= 0)
                return;

            var _dirtyX = (int)Math.Truncate(dirtyX);
            var _dirtyY = (int)Math.Truncate(dirtyY);
            var _dirtyWidth = (int)Math.Truncate(dirtyWidth);
            var _dirtyHeight = (int)Math.Truncate(dirtyHeight);

            // We are using 32 bit color.
            int bytesPerPixel = 4;
            // Where we are going to store our pixel information.
            var pixels = new byte[_dirtyHeight * _dirtyWidth * bytesPerPixel];
            byte[] data = Utils.ConvertJSArrayToByteArray(img.data);
            for (int y = _dirtyY; y < _dirtyHeight + _dirtyY; y++)
            {
                for (int x = _dirtyX; x < _dirtyWidth + _dirtyX; x++)
                {
                    int index = y * (int)img.width * 4 + x * 4;
                    pixels[index] = data[index];
                    pixels[index + 1] = data[index + 1];
                    pixels[index + 2] = data[index + 2];
                    pixels[index + 3] = data[index + 3];
                }
            }
            // Where we are going to store our pixel information.
            // Calculate the stride of the bitmap
            int stride = _dirtyWidth * bytesPerPixel;
            BitmapSource source = BitmapSource.Create(_dirtyWidth, _dirtyHeight, 96, 96, PixelFormats.Pbgra32, null,
                                                      pixels, stride);
            var image = new Image();
            image.Source = source;
            image.SetValue(System.Windows.Controls.Canvas.TopProperty, dy);
            image.SetValue(System.Windows.Controls.Canvas.LeftProperty, dx);
            _surface.Children.Add(image);
        }
        public void drawImage(object pImg, double sx, double sy, double sw, double sh, double dx, double dy, double dw,
                              double dh)
        {
            if (pImg is ImageData)
            {
                string url = ((ImageData)pImg).src;
                var httpRegex = new Regex(@"http://.*");
                var image = new Image();
                var imageSource = new BitmapImage();
                if (httpRegex.IsMatch(url))
                {
                    var client = new WebClient();
                    byte[] bytes = client.DownloadData(url);
                    using (var memoryStream = new MemoryStream(bytes))
                    {
                        imageSource.BeginInit();
                        imageSource.StreamSource = memoryStream;
                        imageSource.EndInit();
                    }
                }
                else
                {
                    imageSource = new BitmapImage();
                    imageSource.BeginInit();
                    imageSource.CacheOption = BitmapCacheOption.OnLoad;
                    imageSource.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    imageSource.UriSource = new Uri(url, UriKind.RelativeOrAbsolute);
                    imageSource.EndInit();
                }
                image.Source = imageSource;

                image.SetValue(System.Windows.Controls.Canvas.TopProperty, dy - sy);
                image.SetValue(System.Windows.Controls.Canvas.LeftProperty, dx - sx);
                var rect = new RectangleGeometry(new Rect(sx, sy, sw, sh));
                image.Clip = rect;
                _surface.Children.Add(image);
            }
            if (OnPartialDraw != null)
            {
                OnPartialDraw();
            }
        }
Example #31
0
        public InfoPageViewModel(RootObject rootObject)
        {
            //this.children = new UIElementCollection(null, null);
            //this.panel = new StackPanel();
            this.collection = new ObservableCollection <Grid>();

            this.rootObject = rootObject;

            for (int i = 0; i < rootObject.payload.Count; i++)
            {
                var  news = rootObject.payload;
                Grid grid = new Grid();
                grid.Width = 1500;

                ColumnDefinition cd1 = new ColumnDefinition();
                cd1.Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star);
                ColumnDefinition cd2 = new ColumnDefinition();
                cd2.Width = new System.Windows.GridLength(2, System.Windows.GridUnitType.Star);
                grid.ColumnDefinitions.Add(cd1);
                grid.ColumnDefinitions.Add(cd2);

                RowDefinition rd1 = new RowDefinition();
                rd1.Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star);
                RowDefinition rd2 = new RowDefinition();
                rd2.Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star);
                grid.RowDefinitions.Add(rd1);
                grid.RowDefinitions.Add(rd2);

                Image image = new Image();
                //BitmapImage bitmapImage = new BitmapImage(new Uri(news[i].url));
                //bitmapImage.DownloadCompleted += (sender, e) => BitmapImage_DownloadCompleted(sender, e, image);

                // souce = payload.source
                //Binding bind = new Binding(String.Format("rootObject.payload[{0}].source", i));
                //image.SetBinding(Image.SourceProperty, bind);

                image.Source = rootObject.payload[i].source;
                image.Width  = 250;
                image.SetValue(Grid.RowProperty, 0);
                image.SetValue(Grid.ColumnProperty, 0);
                image.SetValue(Grid.RowSpanProperty, 2);
                //image.Margin = new System.Windows.Thickness(5, 0, 0, 0);

                grid.Children.Add(image);

                TextBlock title = new TextBlock();
                title.Text = news[i].title;
                title.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                title.FontSize            = 30.0;
                title.SetValue(Grid.ColumnProperty, 1);
                title.SetValue(Grid.RowProperty, 0);
                grid.Children.Add(title);

                TextBlock description = new TextBlock();
                description.Width               = 250;
                description.TextWrapping        = System.Windows.TextWrapping.WrapWithOverflow;
                description.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                description.Background          = (SolidColorBrush)(new BrushConverter().ConvertFrom(news[i].color));
                description.Text = news[i].type;
                description.SetValue(Grid.ColumnProperty, 1);
                description.SetValue(Grid.RowProperty, 2);
                grid.Children.Add(description);
                grid.Margin = new System.Windows.Thickness(0, 100, 0, 0);

                this.collection.Add(grid);
                //panel.Children.Add(grid);
                //children.Add(grid);
                //mainStackPanel.Children.Add(grid);
            }
        }
Example #32
0
 public static void SetCacheHeight(Image obj, double value)
 {
     obj.SetValue(CacheHeightProperty, value);
 }
Example #33
0
        public override void SetupCustomUIElements(Controls.dynNodeView nodeUI)
        {
            image1 = new System.Windows.Controls.Image
                {
                    //Width = 320,
                    //Height = 240,
                    MaxWidth = 400,
                    MaxHeight = 400,
                    Margin = new Thickness(5),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                    Name = "image1",
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };

            //nodeUI.inputGrid.Children.Add(image1);
            nodeUI.grid.Children.Add(image1);
            image1.SetValue(Grid.RowProperty, 2);
            image1.SetValue(Grid.ColumnProperty, 0);
            image1.SetValue(Grid.ColumnSpanProperty, 3);
        }
Example #34
0
 public static void SetDisplayErrorThumbnailOnError(Image obj, bool value)
 {
     obj.SetValue(DisplayErrorThumbnailOnErrorProperty, value);
 }
 public void ResetBullet(System.Windows.Controls.Image bullet, int row)
 {
     bullet.Visibility = Visibility.Collapsed;
     bullet.Margin     = new Thickness(0);
     bullet.SetValue(Grid.RowProperty, row);
 }
        private Size LoadImageFromUrl(string url, double dy, double dx)
        {
            var image = new Image();
            //load image into Bitmap
            Bitmap bmp = Utils.GetBitmapFromUrl(url);
            var ms = new MemoryStream();
            bmp.Save(ms, ImageFormat.Png);
            //convert Drawing.Bitmap to Media.BitmapImage
            var bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.StreamSource = ms;
            bitmapImage.EndInit();
            bitmapImage.Freeze();
            //assign image's source
            image.Source = bitmapImage;
            image.SetValue(System.Windows.Controls.Canvas.TopProperty, dy);
            image.SetValue(System.Windows.Controls.Canvas.LeftProperty, dx);
            image.Width = bitmapImage.PixelWidth;
            image.Height = bitmapImage.PixelHeight;
            _surface.Children.Add(image);

            return new Size(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
        }