Free Support Forum - aspose.com

Rectangle Annotation with text

Hi. We want be able to apply text annotations in Images. Something like that: 123.png (684 Bytes)

But in Aspose.Imaging is only TextShape, and we can’t set border color of shape, and text is transparent.1.png (16.0 KB)

Does any way to create text annotation in Imaging?

@tvv91,

I have observed your requirements and suggest you to please try using following sample code on your end.

 public  static void TestText()
    {
      String dataDir = @"C:\Imaging Data\";

        dataDir += "Text.bmp";

        // Create an instance of BmpOptions and set its various properties
        BmpOptions imageOptions = new BmpOptions();
        imageOptions.BitsPerPixel = 24;

        // Create an instance of FileCreateSource and assign it to Source property 
        imageOptions.Source = new FileCreateSource(dataDir, false);
        using (var image = Image.Create(imageOptions, 500, 500))
        {
            // create souce image
            {
                var graphics = new Graphics(image);

                // Clear the image surface with white color and Create and initialize a Pen object with blue color
                graphics.Clear(Color.White);
                var pen = new Pen(Color.Blue);
            
                Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 17);

                graphics.DrawRectangle(new Pen(Color.Orange), new Rectangle(30, 100, 200, 130));

                //Create an instance of SolidBrush having Red Color
                Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Black);
                //Draw a String
                //graphics.DrawString("Test Mudassir", font, brush, new Aspose.Imaging.PointF(image.Bounds.Right - 325, image.Bounds.Bottom - 70));
                graphics.DrawString("Test Aspose", font, brush, new Aspose.Imaging.PointF(35, 105));

            }

            image.Save();

        }
    }