Free Support Forum - aspose.com

Annotations feature for images

Is there any Annotations feature for images just like we have for PDF.

@srikanthgupta.maple,

Aspose.Imaging supports adding text and that you may use as annotation on your image. Please check the following sample code on your end.

string path = "c:\\aspose.work\\";

float fontSize = 40;
string textAnnotation = "some text";

using (System.Drawing.Image image = System.Drawing.Image.FromFile(path + "input.png"))
{
    System.Drawing.StringFormat format = new System.Drawing.StringFormat();
    format.Alignment = System.Drawing.StringAlignment.Near;
    format.FormatFlags = System.Drawing.StringFormatFlags.MeasureTrailingSpaces;

    using (System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red))
    {
        using (System.Drawing.Font font = new System.Drawing.Font("Arial", fontSize))
        {
            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image))
            {
                System.Drawing.Drawing2D.Matrix matrix1 = new System.Drawing.Drawing2D.Matrix();
                matrix1.Translate(110, 60);
                graphics.Transform = matrix1;

                graphics.DrawString(textAnnotation, font, brush, 0, 0, format);

                System.Drawing.Drawing2D.Matrix matrix2 = new System.Drawing.Drawing2D.Matrix();
                matrix2.Translate(110, 60);
                matrix2.Rotate(90);
                graphics.Transform = matrix2;

                graphics.DrawString(textAnnotation, font, brush, 0, 0, format);

                image.Save(path + "result_gdi.png");
            }
        }
    }
}