示例#1
0
 public DrawingPage(RootObject rootObj, Image img)
 {
     InitializeComponent();
     this.rootObject = rootObj;
     this.image      = img;
 }
        private void DrawView(RootObject rootObject, Image img)
        {
            Stream streamD = null;
            var    width   = img.Width;
            var    height  = img.Height;

            if (rootObject != null && rootObject.predictions.Count > 0)
            {
                //  beerRecognizedList = new List<RootObject>();
                //processedImage.Image = pcbOriginal.Image;
                //processedImage.SizeMode = PictureBoxSizeMode.StretchImage;
                int i = 0;
                foreach (var item in rootObject.predictions)
                {
                    if (item.probability > .50)
                    {
                        var bitmap = SKBitmap.Decode(App.CroppedImage);

                        // create a canvas for drawing
                        var canvas = new SKCanvas(bitmap);

                        // draw a rectangle with a red border
                        var paint = new SKPaint
                        {
                            Style       = SKPaintStyle.Stroke,
                            Color       = SKColors.Red,
                            StrokeWidth = 5
                        };

                        canvas.DrawRect(SKRect.Create(10, 10, 10, 10), paint);

                        // get an image subset to save
                        var im     = SKImage.FromBitmap(bitmap);
                        var subset = im.Subset(SKRectI.Create(20, 20, 90, 90));

                        // encode the image
                        var encodedData = im.Encode(SKEncodedImageFormat.Png, 75);

                        // get a stream that can be saved to disk/memory/etc
                        var stream = encodedData.AsStream();

                        image.Source = ImageSource.FromStream(() => streamD);

                        Content = image;
                    }
                }



                //foreach (var item in rootObject.predictions)
                //{
                //    if (item.probability > .50)
                //    {
                //        var left = item.boundingBox.left * width;
                //        var top = item.boundingBox.top * height;
                //        var widthX = item.boundingBox.width * width;
                //        var heightY = item.boundingBox.height * height;

                //        canvas.DrawRect(SKRect.Create((float)left, (float)top, (float)widthX, (float)heightY), paint);

                //        // get an image subset to save
                //        //var image = SKImage.FromBitmap(bitmap);
                //        //var subset = image.Subset(SKRectI.Create(Convert.ToInt32(left), Convert.ToInt32(top), Convert.ToInt32(widthX), Convert.ToInt32(heightY)));

                //        // encode the image
                //        //var encodedData = subset.Encode(SKEncodedImageFormat.Png, 100);

                //        // get a stream that can be saved to disk/memory/etc
                //        //streamD= encodedData.AsStream();
                //    }
                //}
                //image.Source = ImageSource.FromStream(() => streamD);

                //Content = image;
            }
        }