Solved

PixTools - Invalid image color format - during annotation (MergeAnnotations)

Posted on 2012-04-12
3
1,111 Views
Last Modified: 2012-04-18
I could use some help with an error I am getting when trying to annotate a TIFF image with some text.
 
00:00:06.0127 (Error): An error occured while attempting to export the file in t
he ExportFiles method of the ExportGroup class.  Message is : Invalid image colo
r format. System.InvalidOperationException: Invalid image color format.
   at PixTools.PixImage.MergeAnnotations(AnnotationDocument annotations, MergeAt
tributes attrs, PixImageTransformer transformer)
   at MetaSource.Imaging.Services.Impl.LeadToolsAnnotate.Annotate(MemoryStream I
nputImage, String AnnotationText, Font AnnotationFont)
 
 
The error is being raised on this line of code:
 
PixImage newpi = pImage.MergeAnnotations(annotationDoc, MergeAttributes.None, null);
 
 
Here is the entire block of code:
 
 
        public MemoryStream Annotate(MemoryStream InputImage, string AnnotationText, Font AnnotationFont)
        {
            InputImage.Position = 0;
           
            Bitmap bImagem = new Bitmap(InputImage);
            PixImage pImage = new PixImage();
            pImage.Import(bImagem);
            PixTools.Annotation.AnnotationDocument annotationDoc = new PixTools.Annotation.AnnotationDocument();
            PixTools.Annotation.TextAnnotation textItem = new PixTools.Annotation.TextAnnotation();
            textItem.Text = new PixTools.Annotation.ItemText(AnnotationText);
            annotationDoc.Items.Add(textItem);
 
//raises an exception when this line attempts to run
            PixImage newpi = pImage.MergeAnnotations(annotationDoc, MergeAttributes.None, null);
           
            Bitmap anotherBitmap = newpi.GetBitmap();
 
 
            MemoryStream ms = new MemoryStream();
            // Save to memory using the Jpeg format
            anotherBitmap.Save(ms, ImageFormat.Tiff);
 
 
            ms.Position = 0;
 
 
            return ms;
 
            //annotationDoc.Items.Clear();
        }
 
 
The intent of the code is to annotate the image  (which is passed in as a MemoryStream object) with the text that is passed in.
0
Comment
Question by:knowlton
  • 2
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37842758
I would think that Reflector, or some other decompiler (JustDecompile, ILSpy, ...) would help explain where the exception is coming from, and what the expectation is.
0
 
LVL 5

Accepted Solution

by:
knowlton earned 0 total points
ID: 37842770
Here is the corrected code (notice the bolded code):

public MemoryStream Annotate(MemoryStream InputImage, string AnnotationText, Font AnnotationFont)
        {
            InputImage.Position = 0;
            
            Bitmap bImagem = new Bitmap(InputImage);
            PixImage pImage = new PixImage();
            pImage.Import(bImagem);
            PixTools.Annotation.AnnotationDocument annotationDoc = new PixTools.Annotation.AnnotationDocument();
            PixTools.Annotation.TextAnnotation textItem = new PixTools.Annotation.TextAnnotation();
            textItem.Text = new PixTools.Annotation.ItemText(AnnotationText);
            annotationDoc.Items.Add(textItem);
            Console.WriteLine("LEAD TOOLS ANNOTATE - no print top");
           [b] PixImage newpi = pImage.MergeAnnotations(annotationDoc, MergeAttributes.MergeColorFormatPreserve, null);[/b]
            
            Bitmap anotherBitmap = newpi.GetBitmap();

            MemoryStream ms = new MemoryStream();
            
            anotherBitmap.Save(ms, ImageFormat.Tiff);

            ms.Position = 0;

            return ms;
      
            //annotationDoc.Items.Clear();
        }

Open in new window

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 37859686
Great suggestions!

In the end, it was just trial and error.  Since there's no way for me to share the PixTools libraries, there's no way for anyone on EE to see the code completion or know what options I had available.

The corrected code has been published.  Someone else may be using PixTools and run into this problem.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now