コード例 #1
0
        void tsbAnnotation_Click(object sender, EventArgs e)
        {
            //Depending on the presence or absence of annotation, to display the confirmation message.
            if (arvMain.Document.Pages[arvMain.ReportViewer.CurrentPage - 1].Annotations.Count > 0)
            {
                MessageBox.Show(Resource1.String1, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // Gets the image from a resource seal.
            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream file     = thisExe.GetManifestResourceStream("GrapeCity.ActiveReports.Sample.CustomAnnotation.Resources.stamp.png");
            Bitmap           imgStamp = new Bitmap(file);
            // Create an annotation, you can assign the value of the property.
            AnnotationImage annoImg = new AnnotationImage();

            annoImg.BackgroundImage  = imgStamp;                                      // Image
            annoImg.Color            = Color.Transparent;                             //Background color
            annoImg.BackgroundLayout = Document.Section.Annotations.ImageLayout.Zoom; // Display format
            annoImg.ShowBorder       = false;                                         //Display border (hidden)
            // Add a comment.
            // (Specify the additional position)
            annoImg.Attach(6.09F, 1.19F);
            arvMain.Document.Pages[arvMain.ReportViewer.CurrentPage - 1].Annotations.Add(annoImg);
            // (Set the size)
            annoImg.Height = 0.7F;
            annoImg.Width  = 0.7F;
            //To update the Viewer.
            arvMain.Refresh();
        }
コード例 #2
0
ファイル: DrawHelper.cs プロジェクト: LKneringer/Alturos.Yolo
        public static Image DrawBoxes(AnnotationImage image)
        {
            var originalBitmap = new Bitmap(image.ImagePath);
            var bitmap         = new Bitmap(originalBitmap, ImageSize);

            originalBitmap.Dispose();

            return(bitmap);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: HappyKiwiSyu/Alturos.Yolo
        private void ImageEdited(AnnotationImage annotationImage)
        {
            if (annotationImage == null)
            {
                return;
            }

            annotationImage.Package.IsDirty = true;

            annotationImage.Package.UpdateAnnotationStatus(annotationImage);
            this.annotationPackageListControl.RefreshData();
        }
コード例 #4
0
        private void AddEmbeddedImage()
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Images|*.jpg;*.png;*.tif";
            if (dlg.ShowDialog().Value)
            {
                AnnotationImage            image = new AnnotationImage(dlg.FileName);
                WpfEmbeddedImageAnnotation ann   = new WpfEmbeddedImageAnnotation(image, new Point(0, 0), null, new Point(0, 0));
                this.AnnotationViewer.Annotations.CreateAnnotation(ann);
            }
        }
コード例 #5
0
ファイル: DrawHelper.cs プロジェクト: radtek/Alturos.Yolo
        public static Image DrawBoxes(AnnotationImage image, List <ObjectClass> objectClasses)
        {
            var colorCodes = GetColorCodes();

            var items = image.BoundingBoxes;

            var originalBitmap = new Bitmap(image.FilePath);
            var bitmap         = new Bitmap(originalBitmap, ImageSize);

            originalBitmap.Dispose();

            using (var canvas = Graphics.FromImage(bitmap))
            {
                foreach (var item in items)
                {
                    var width  = item.Width * bitmap.Width;
                    var height = item.Height * bitmap.Height;
                    var x      = (item.CenterX * bitmap.Width) - (width / 2);
                    var y      = (item.CenterY * bitmap.Height) - (height / 2);

                    var color = ColorTranslator.FromHtml(colorCodes[item.ObjectIndex]);
                    using (var pen = new Pen(color, 3))
                    {
                        canvas.DrawRectangle(pen, x, y, width, height);

                        var objectClass = objectClasses?.FirstOrDefault(o => o.Id == item.ObjectIndex);
                        if (objectClass != null)
                        {
                            using (var brush = new SolidBrush(color))
                                using (var bgBrush = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                                    using (var font = new Font("Arial", 20))
                                    {
                                        var text  = $"{objectClass.Id} {objectClass.Name}";
                                        var point = new PointF(x + 4, y + 4);
                                        var size  = canvas.MeasureString(text, font);

                                        canvas.FillRectangle(bgBrush, point.X, point.Y, size.Width, size.Height);
                                        canvas.DrawString(text, font, brush, point);
                                    }
                        }
                    }
                }

                canvas.Flush();
            }

            return(bitmap);
        }
コード例 #6
0
        private void ImageSelected(AnnotationImage image)
        {
            this.annotationDrawControl.SetImage(image);

            // Failsafe, because ImageSelected is triggered when the package is changed. We don't want to select the image in this case.
            if (this._changedPackage)
            {
                return;
            }

            if (image == null)
            {
                return;
            }

            this.annotationDrawControl.ApplyCachedBoundingBox();
        }
コード例 #7
0
        private void DataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            var image = this.dataGridView1.CurrentRow?.DataBoundItem as AnnotationImage;

            if (image == null)
            {
                return;
            }

            if (this._cachedImage == image)
            {
                return;
            }
            this._cachedImage = image;

            this.ImageSelected?.Invoke(image);
        }
コード例 #8
0
        public void SetImage(AnnotationImage image, List <ObjectClass> objectClasses)
        {
            var oldImage = this.pictureBox1.Image;

            if (image == null)
            {
                this.pictureBox1.Image = null;
            }
            else
            {
                this.pictureBox1.Image = DrawHelper.DrawBoxes(image, objectClasses);
            }

            if (oldImage != null)
            {
                oldImage.Dispose();
            }
        }
コード例 #9
0
        public static Image DrawBoxes(AnnotationImage image)
        {
            try
            {
                var originalBitmap = new Bitmap(image.ImagePath);

                var newImageSize = new Size();
                if (originalBitmap.Width > ImageSize.Width)
                {
                    newImageSize.Height =
                        (int)(originalBitmap.Height * (ImageSize.Width / (double)originalBitmap.Width));
                    newImageSize.Width = ImageSize.Width;
                }

                if (originalBitmap.Height > ImageSize.Height)
                {
                    newImageSize.Width =
                        (int)(originalBitmap.Width * (ImageSize.Height / (double)originalBitmap.Height));
                    newImageSize.Height = ImageSize.Height;
                }

                var resizedBitmap = new Bitmap(originalBitmap, newImageSize);
                foreach (var id in originalBitmap.PropertyIdList)
                {
                    resizedBitmap.SetPropertyItem(originalBitmap.GetPropertyItem(id));
                }

                originalBitmap.Dispose();

                return(resizedBitmap);
            }
            catch (Exception)
            {
                var bitmap = new Bitmap(ImageSize.Width, ImageSize.Height);
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.Clear(Color.White);
                }

                return(bitmap);
            }
        }
コード例 #10
0
        public void SetImage(AnnotationImage image)
        {
            this.CacheLastBoundingBoxes();

            this._annotationImage = image;
            var oldImage = this.pictureBox1.Image;

            if (image == null)
            {
                this.pictureBox1.Image = null;
            }
            else
            {
                this.pictureBox1.Image = DrawHelper.DrawBoxes(image);
            }

            if (oldImage != null)
            {
                oldImage.Dispose();
            }
        }
コード例 #11
0
        public async Task <bool> DeleteImageAsync(AnnotationImage image)
        {
            try
            {
                // Delete image from S3
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = this._bucketName,
                    Key        = $"{image.Package.PackageName.ReplaceSpecialCharacters()}/{image.ImageName.ReplaceSpecialCharacters()}"
                };

                var response = await this._s3Client.DeleteObjectAsync(deleteObjectRequest).ConfigureAwait(false);

                // Delete image from DynamoDB
                using (var context = new DynamoDBContext(this._dynamoDbClient))
                {
                    var dbConfig = new DynamoDBOperationConfig
                    {
                        OverrideTableName = this._dbTableName
                    };
                    var package = await context.LoadAsync <AnnotationPackageDto>(image.Package.ExternalId, dbConfig).ConfigureAwait(false);

                    package.Images?.RemoveAll(o => o.ImageName.Equals(image.ImageName));
                    await context.SaveAsync(package, dbConfig).ConfigureAwait(false);
                }

                // Delete local image
                var localImagePath = Path.Combine(this._extractionFolder, image.Package.PackageName, image.ImageName);
                if (File.Exists(localImagePath))
                {
                    File.Delete(localImagePath);
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #12
0
 private void ImageSelected(AnnotationImage image)
 {
     this.annotationImageControl.SetImage(image, this._objectClasses);
 }