Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

13 Experts available now in Live!

Get 1:1 Help Now