Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-04-12
3
Medium Priority
?
1,181 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:Tom 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:
Tom 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:Tom 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview

916 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