Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Annotate JPG Images using C#
Annotate JPG Images using C#
1. Add Multiple Annotations to JPG Images
2. Add Area Annotation to JPG Images
3. Add TextField Annotation to JPG Images
4. Add Watermark Annotation to JPG Images
// intialize annotator
Annotator annotator = new Annotator("C:\\Files\\sample.jpg");
// define area annotation
AreaAnnotation area = new AreaAnnotation();
area.BackgroundColor = 65535;
area.Box = new Rectangle(80, 575, 310, 50);
area.CreatedOn = DateTime.Now;
area.Opacity = 0.7;
area.PageNumber = 0;
area.PenColor = 65535;
area.PenStyle = PenStyle.Dot;
area.PenWidth = 3;
// add area annotation
annotator.Add(area);
// save the output file
annotator.Save("C:\\Files\\result.jpg");
// intialize annotator
Annotator annotator = new Annotator("C:\\Files\\sample.jpg");
List<AnnotationBase> annotations = new List<AnnotationBase>();
// define and add arrow annotation
ArrowAnnotation arrow = new ArrowAnnotation
{
Box = new Rectangle(100, 100, 100, 100),
CreatedOn = DateTime.Now,
Opacity = 0.7,
PenColor = 16777215,
PenStyle = PenStyle.DashDotDot,
PenWidth = 5
};
annotations.Add(arrow);
// define and add distance annotation
DistanceAnnotation distance = new DistanceAnnotation
{
Box = new Rectangle(75, 545, 315, 0),
CreatedOn = DateTime.Now,
Opacity = 0.7,
PenColor = 65535,
PenStyle = PenStyle.Solid,
PenWidth = 9
};
annotations.Add(distance);
// define and add ellipse annotation
EllipseAnnotation ellipse = new EllipseAnnotation
{
BackgroundColor = 65535,
Box = new Rectangle(150, 300, 100, 100),
CreatedOn = DateTime.Now,
Opacity = 0.3,
PenColor = 65535,
PenStyle = PenStyle.Dot,
PenWidth = 3
};
annotations.Add(ellipse);
// define and add point annotation
PointAnnotation point = new PointAnnotation
{
Box = new Rectangle(75, 605, 10, 10),
CreatedOn = DateTime.Now,
};
annotations.Add(point);
// add annotations to annotator
annotator.Add(annotations);
// save the output file
annotator.Save("C:\\Files\\result.jpg");
// intialize annotator
Annotator annotator = new Annotator("C:\\Files\\sample.jpg");
// define text field annotation
TextFieldAnnotation textField = new TextFieldAnnotation();
textField.Box = new Rectangle(130, 120, 270, 30);
textField.CreatedOn = DateTime.Now;
textField.Text = "Document Automation APIs";
textField.FontColor = 16777215;
textField.FontSize = 12;
textField.Opacity = 1;
textField.PenStyle = PenStyle.Dot;
textField.PenWidth = 3;
textField.FontFamily = "Arial";
textField.TextHorizontalAlignment = HorizontalAlignment.Center;
// add text field annotation
annotator.Add(textField);
// save the output file
annotator.Save("C:\\Files\\result.jpg");
// initialize annotator
Annotator annotator = new Annotator("C:\\Files\\sample.jpg");
// define watermark annotation
WatermarkAnnotation watermark = new WatermarkAnnotation();
watermark.Text = "This is a sample Watermark";
watermark.FontColor = 16777215;
watermark.FontSize = 22;
watermark.Opacity = 0.7;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
watermark.VerticalAlignment = VerticalAlignment.Center;
// add watermark annotation
annotator.Add(watermark);
// save the output file
annotator.Save("C:\\Files\\result.jpg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment