Solved

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

Posted on 2012-04-12
3
1,117 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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