Как аннотировать TIFF-файл?
В этом разделе
Вот C#/VB.NET код, который демонстрирует, как загрузить изображение из TIFF-файла, добавить аннотации к изображению, сохранить изображение с аннотациями в новый TIFF-файл.
private static void AnnotateTiffUsingTemporaryFile()
{
// create image collection
Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection();
// create annotation controller associated with image collection
Vintasoft.Imaging.Annotation.AnnotationDataController annotations =
new Vintasoft.Imaging.Annotation.AnnotationDataController(images);
// load TIFF file into collection
images.Add("sourceTiffFile.tif");
// get annotation collection for selected image
Vintasoft.Imaging.Annotation.AnnotationDataCollection imageAnnotations = annotations[images.Count - 1];
// create new annotation
Vintasoft.Imaging.Annotation.RectangleAnnotationData anno =
new Vintasoft.Imaging.Annotation.RectangleAnnotationData();
anno.Size = new System.Drawing.SizeF(300, 300);
anno.FillBrush = new Vintasoft.Imaging.Annotation.AnnotationSolidBrush(System.Drawing.Color.AliceBlue);
anno.Location = new System.Drawing.PointF(0, 0);
// add new annotation into annotation collection
imageAnnotations.Add(anno);
Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder =
new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();
// specify that annotations must be saved with image collection
encoder.AnnotationsFormat = Vintasoft.Imaging.AnnotationsFormat.VintasoftBinary;
// save image collection synchronously to new file
images.SaveSync("destTiffFile.tif", encoder);
}
Private Shared Sub AnnotateTiffUsingTemporaryFile()
' create image collection
Dim images As New Vintasoft.Imaging.ImageCollection()
' create annotation controller associated with image collection
Dim annotations As New Vintasoft.Imaging.Annotation.AnnotationDataController(images)
' load TIFF file into collection
images.Add("sourceTiffFile.tif")
' get annotation collection for selected image
Dim imageAnnotations As Vintasoft.Imaging.Annotation.AnnotationDataCollection = annotations(images.Count - 1)
' create new annotation
Dim anno As New Vintasoft.Imaging.Annotation.RectangleAnnotationData()
anno.Size = New System.Drawing.SizeF(300, 300)
anno.FillBrush = New Vintasoft.Imaging.Annotation.AnnotationSolidBrush(System.Drawing.Color.AliceBlue)
anno.Location = New System.Drawing.PointF(0, 0)
' add new annotation into annotation collection
imageAnnotations.Add(anno)
Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder()
' specify that annotations must be saved with image collection
encoder.AnnotationsFormat = Vintasoft.Imaging.AnnotationsFormat.VintasoftBinary
' save image collection synchronously to new file
images.SaveSync("destTiffFile.tif", encoder)
End Sub
Вот C#/VB.NET код, который демонстрирует, как загрузить изображение из TIFF-файлf, добавить аннотации к изображению и сохранить изображение с аннотациями обратно в исходный TIFF-файл.
Временный файл не используется.
private static void AnnotateTiffWithoutUsingTemporaryFile()
{
// open stream of the TIFF file
System.IO.FileStream stream = new System.IO.FileStream(
"sourceTiffFile.tif", System.IO.FileMode.Open);
// create image collection
Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection();
// create annotation controller associated with image collection
Vintasoft.Imaging.Annotation.AnnotationDataController annotations =
new Vintasoft.Imaging.Annotation.AnnotationDataController(images);
// add images (pages of TIFF file) from the stream to the image collection
images.Add(stream);
// get annotation collection for selected image
Vintasoft.Imaging.Annotation.AnnotationDataCollection imageAnnotations = annotations[images.Count - 1];
// create new annotation
Vintasoft.Imaging.Annotation.RectangleAnnotationData anno = new
Vintasoft.Imaging.Annotation.RectangleAnnotationData();
anno.Size = new System.Drawing.SizeF(300, 300);
anno.FillBrush = new Vintasoft.Imaging.Annotation.AnnotationSolidBrush(System.Drawing.Color.AliceBlue);
anno.Location = new System.Drawing.PointF(0, 0);
// add new annotation into annotation collection
imageAnnotations.Add(anno);
Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder =
new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();
// specify that annotations must be saved with image collection
encoder.AnnotationsFormat = Vintasoft.Imaging.AnnotationsFormat.VintasoftBinary;
// specify that image collection must be saved to the source stream
encoder.SaveAndSwitchSource = true;
// save image collection synchronously to the source stream (save changes in TIFF file)
images.SaveSync(stream, encoder);
// close the stream of TIFF file
stream.Close();
}
Private Shared Sub AnnotateTiffWithoutUsingTemporaryFile()
' open stream of the TIFF file
Dim stream As New System.IO.FileStream("sourceTiffFile.tif", System.IO.FileMode.Open)
' create image collection
Dim images As New Vintasoft.Imaging.ImageCollection()
' create annotation controller associated with image collection
Dim annotations As New Vintasoft.Imaging.Annotation.AnnotationDataController(images)
' add images (pages of TIFF file) from the stream to the image collection
images.Add(stream)
' get annotation collection for selected image
Dim imageAnnotations As Vintasoft.Imaging.Annotation.AnnotationDataCollection = annotations(images.Count - 1)
' create new annotation
Dim anno As New Vintasoft.Imaging.Annotation.RectangleAnnotationData()
anno.Size = New System.Drawing.SizeF(300, 300)
anno.FillBrush = New Vintasoft.Imaging.Annotation.AnnotationSolidBrush(System.Drawing.Color.AliceBlue)
anno.Location = New System.Drawing.PointF(0, 0)
' add new annotation into annotation collection
imageAnnotations.Add(anno)
Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder()
' specify that annotations must be saved with image collection
encoder.AnnotationsFormat = Vintasoft.Imaging.AnnotationsFormat.VintasoftBinary
' specify that image collection must be saved to the source stream
encoder.SaveAndSwitchSource = True
' save image collection synchronously to the source stream (save changes in TIFF file)
images.SaveSync(stream, encoder)
' close the stream of TIFF file
stream.Close()
End Sub