VintaSoft Annotation .NET Plug-in Discussions
Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.
Board index < VintaSoft Imaging < VintaSoft Annotation .NET Plug-in Discussions
foreach(image in collection)
foreach(page in image)
{
TextAnnotation header = new TextAnnotation();
header.Text...
header.Location...
header.Size...
annotationViewer.SelectedAnnotationCollection.Add(header);
annotationViewer.Annotations.MergeImageWithAnnotations(current_page_index);
}
If there is another way, I'd be very interested in know how this can be done.// create image collection AND load multipage TIFF file into collection
ImageCollection images = new ImageCollection();
images.Add("multipage.tif");
// create annotation controller which will manage annotations of image collection AND
// link image collection and annotation controller
AnnotationController annotations = new AnnotationController(images);
// for each image in image collection
for (int i = 0; i < images.Count; i++)
{
// create the Stamp annotation
StampAnnotation stamp = new StampAnnotation();
stamp.Text = "Approved";
stamp.StampColor = Color.Blue;
stamp.Rotation = -30;
stamp.Location = new PointF(images[i].Width / 2, images[i].Height / 2);
stamp.Size = new SizeF(images[i].Width / 3 * 2, images[i].Height / 5);
annotations[i].Add(stamp);
// merge image with annotation
annotations.MergeImageWithAnnotations(i);
}
Best regards, Alexander
using (ImageCollection images = new ImageCollection())
{
foreach (var file in files)
{
images.Add(file);
}
var cont = new AnnotationController(images);
images.SetSaveAnnotations(true);
images.SaveAndSwitchSource = false;
var encoder = new TiffEncoder();
// for each image in image collection
for (int i = 0; i < images.Count; i++)
{
cont.MergeImageWithAnnotations(i);
}
//save the images
foreach (var file in files)
{
images.SaveAsync(file);
//images.SaveSync(file);
}
// images.ClearAndDisposeItems();
}
void MergeImagesWithAnnotations(string filename)
{
using (Stream sourceStream = File.Open(filename, FileMode.Open, FileAccess.ReadWrite))
{
ImageCollection images = new ImageCollection();
images.Add(sourceStream);
AnnotationController controller = new AnnotationController(images);
for (int i = 0; i < images.Count; i++)
{
// add test annotation
TextAnnotation text = new TextAnnotation();
text.Size = new SizeF(100, 100);
text.Location = new PointF(images[i].Width / 2, images[i].Height / 2);
text.Text = "Test";
controller.GetAnnotations(i).Add(text);
}
for (int i = 0; i < images.Count; i++)
controller.MergeImageWithAnnotations(i);
EncoderBase encoder = AvailableEncoders.CreateEncoder(filename);
if (encoder is MultipageEncoderBase)
{
images.SaveAndSwitchSource = true;
images.SaveSync(sourceStream, (MultipageEncoderBase)encoder);
}
else
{
encoder.SaveAndSwitchSource = true;
images[0].Save(sourceStream, encoder);
}
images.ClearAndDisposeItems();
}
}
void MergeImageFilesWithAnnotations(string[] filenames)
{
foreach (string filename in filenames)
MergeImagesWithAnnotations(filename);
}