Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-04-12
3
Medium Priority
?
1,163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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