/// <summary> /// Annotate a tiff file with text. /// </summary> /// <param name="imagePath">the image path to annotate on.</param> /// <param name="targetPath">the target path for the annotated image (ommit to save as source).</param> /// <param name="printText">The string to print.</param> /// <param name="smallFont">Use smaller font.</param> /// <param name="position">The position to print on the image (do not use Middle, as this will be changed to Top, as middle alignment does not exist in this fast mode).</param> /// <returns>true when successfull, false when failed.</returns> /// <remarks>other properties as text roatation are available via further coding.</remarks> public static bool AnnotateTiff(string imagePath, string targetPath, string printText, bool smallFont, ContentAlignment position) { bool result = false; try { //-- Define position --\\ PlacementHorizontal pos = PlacementHorizontal.BottomCenter; switch (position) { //-- Default, not required --\\ //case ContentAlignment.BottomCenter: // pos = PlacementHorizontal.BottomCenter; // break; case ContentAlignment.BottomLeft: pos = PlacementHorizontal.BottomLeft; break; case ContentAlignment.BottomRight: pos = PlacementHorizontal.BottomRight; break; case ContentAlignment.MiddleCenter: pos = pos = PlacementHorizontal.TopCenter; break; case ContentAlignment.MiddleLeft: pos = PlacementHorizontal.TopLeft; break; case ContentAlignment.MiddleRight: pos = PlacementHorizontal.TopRight; break; case ContentAlignment.TopCenter: pos = PlacementHorizontal.TopCenter; break; case ContentAlignment.TopLeft: pos = PlacementHorizontal.TopLeft; break; case ContentAlignment.TopRight: pos = PlacementHorizontal.TopRight; break; } //-- Prepare annotation info --\\ return(AnnotateTiff(imagePath, targetPath, printText, smallFont, pos)); } catch (Exception ex) { ILog.LogError(ex); } return(result); }
/// <summary> /// Annotate a tiff file with text. /// </summary> /// <param name="imagePath">the image path to annotate on.</param> /// <param name="targetPath">the target path for the annotated image (ommit to save as source).</param> /// <param name="printText">The string to print.</param> /// <param name="smallFont">Use smaller font.</param> /// <param name="position">The position to print on the image.</param> /// <returns>true when successfull, false when failed.</returns> /// <remarks>other properties as text roatation are available via further coding.</remarks> private static bool AnnotateTiff(string imagePath, string targetPath, string printText, bool smallFont, PlacementHorizontal position) { TiffDLL obj = new TiffDLL(); bool result = false; try { obj._RegistrationCode = GetRegCode(multiPL); obj._OpenFile.Filename = imagePath; obj._SaveFile.OverwriteFile = OverwriteFile.Overwrite; obj._SaveFile.Format = Format.TIFF_CCITT4_1bit; obj._SaveFile.Filename = string.IsNullOrEmpty(targetPath) ? imagePath : targetPath; if (!Directory.Exists(Path.GetDirectoryName(obj._SaveFile.Filename))) { Directory.CreateDirectory(Path.GetDirectoryName(obj._SaveFile.Filename)); } obj._AnnotationSimple.PlacementHorizontal = position; obj._AnnotationSimple.SmallerFont = smallFont; obj._AnnotationSimple.Text = printText; obj._AnnotationSimple.Opaque = true; //-- Perform the annotation --\\ int res = obj.Run(); if (res != 0) { ILog.LogWarning("Tiff annotate file [{0}] as file [{1}] with text [{2}] at position [{5}], error code [{3}], method [{4}]", imagePath, targetPath, printText, res, MethodBase.GetCurrentMethod().Name, position); return(false); } result = File.Exists(targetPath); } catch (Exception ex) { ILog.LogError(ex); } finally { if (obj != null) { obj._SaveFile = new Save(); obj._OpenFile = new Open(); obj = null; } } return(result); }