Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Re: FaxG4 to RasPdf inverts colors
Started by Kevin B at 08-22-2007 14:01. Topic has 9 replies.

Print Search « Previous Thread Next Thread »
  08-22-2007, 14:01
Kevin B is not online. Last active: 11/15/2007 9:56:39 PM Kevin B

Top 150 Posts
Joined on 04-11-2007
Posts 18
FaxG4 to RasPdf inverts colors
Reply Quote
When I scanned in an image as a RasterImageFormat.FaxG4 and then tried to save that image with RasterCodecs.Save(...) as a RasterImageFormat.RasPdf the resulting pdf file had the right image but the colors were inverted.  That is the background should have been white but it was black, and the text should have been black but it was white.

If I save it in RasPdfG4 it works fine.  However, I want to make sure I can save it as RasPdf if I need to.  Any idea why it inverted the colors and/or how I can avoid it?

One other rider question.  Is there any way to determine the RasterImageFormat of a given RasterImage object?  In other words, can you write a function which given a RasterImage as a parameter can return the RasterImageFormat of that image?

Thanks,
Kevin Berridge

   Report 
  08-24-2007, 10:19
GregR is not online. Last active: 10/10/2008 11:46:18 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,621
Re: FaxG4 to RasPdf inverts colors
Reply Quote
This is likely a difference in palettes.  Try running the ColorResolutionCommand class before you save the file but use the inverse of the palette that the source image was using.  This might also work if you load the image as 24bpp rather than 1, and then save it back out as a 1bpp RasPdf since 24bpp images don't have palettes. 

If this doesn't work, please post a small sample project (NOT your entire application) that isolates this problem so I can reproduce it here.

NOTE: If you are attaching a project or file to the forums...
1.) Zip the file(s) up.
2.) Make sure it is less than 5 MB.  If it is larger, please send an email to support@leadtools.com or  give us your email address and we'll send you FTP instructions.
3.) Remove ANY AND ALL unlock codes and LEADTOOLS DLLs.
4.) Do not click the preview button, the attachment will not show up when you post it.
 
If you do not wish to post your file(s) on the forum since they are publically viewable, please send an email to support@leadtools.com and make sure that you include a link to this forum post.


Greg Ross
LEADTOOLS Technical Support
   Report 
  12-19-2007, 13:48
gatorjoe is not online. Last active: 12/19/2007 6:43:45 PM gatorjoe

Not Ranked
Joined on 09-17-2007
Posts 6
Re: FaxG4 to RasPdf inverts colors
Reply Quote

When I try to convert JPG to PDF (RasPdfG4), we also get an inverted document back. Is this similar to what's happening ? I also tried 24bpp and results are the same (inverted).

How do you use the ColorResolutionCommand class ????

Can you post some sample code?

 

Thanks


   Report 
  12-21-2007, 14:21
GregR is not online. Last active: 10/10/2008 11:46:18 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,621
Re: FaxG4 to RasPdf inverts colors
Reply Quote
Check out the .NET help file's documentation on the ColorResolutionCommand for an example.  If you continue to have problems, please send a small sample project (NOT your entire application) that isolates the problem so I can try to reproduce it here.  Also, make sure you attach the source  and result files so i can see exactly what is happening.

Greg Ross
LEADTOOLS Technical Support
   Report 
  03-04-2008, 11:00
SureshMittapalli is not online. Last active: 2/29/2008 4:43:32 PM SureshMittapalli

Top 100 Posts
Joined on 02-29-2008
Posts 22
Re: FaxG4 to RasPdf inverts colors
Reply Quote

Hi,

When I tried to convert an image to pdf , the colors are getting inverted. background is becoming black and letters are displaying in white color. Below is the code which I am using, Could you please look into this and let me know how can I fix this. Please provide some sample code that would fix this problem.

Thanks,

Suresh


 

MemoryStream stream = new MemoryStream();

RasterCodecs codecs = null;

RasterImage img = null;

RasterImageGdiPlusGraphicsContainer container = null;

//Make sure file exists

try

{

RasterCodecs.Startup();

RasterImageFormat imgFormat = RasterImageFormat.RasPdfG4;

codecs = new RasterCodecs();

RasterSupport.Unlock(RasterSupportType.PdfRead, pdfReadKey); //unlock PDF_READ

RasterSupport.Unlock(RasterSupportType.PdfSave, pdfSaveKey); //unlock PDF_SAVE

img = codecs.Load(inputFile); //load input file

container = img.CreateGdiPlusGraphics();

container.Graphics.SmoothingMode = SmoothingMode.None;

container.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

Brush br = new LinearGradientBrush(Point.Empty, new Point(200, 200), Color.Black, Color.Black);

Font textFont = new Font(FontFamily.GenericSansSerif, 12);

PointF point = new PointF(800, 100);

container.Graphics.DrawString("Suresh Test", textFont, br, point);

codecs.Save(img, stream, imgFormat, 0, 1, -1, 1, CodecsSavePageMode.Overwrite);

}


   Report 
  03-05-2008, 9:16
GregR is not online. Last active: 10/10/2008 11:46:18 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,621
Re: FaxG4 to RasPdf inverts colors
Reply Quote
Most likely it's a difference in palettes somewhere along the way, possibly in the Graphics object.  Using the ColorResolutionCommand to reverse the palette before calling CreateGdiPlusGraphics() might do the trick. 

If that doesn't do the trick or you can't find the problem, please send a smal sample project (NOT your entire application) that isolates the problem so i can try to reproduce it here.  Also, send the before and after images so I can see exactly what results you are getting.

NOTE: If you are attaching a project or file to the forums...
1.) Zip the file(s) up.
2.) Make sure it is less than 5 MB.  If it is larger, please send an email to support@leadtools.com and we'll send you FTP instructions.
3.) Remove ANY AND ALL unlock codes and LEADTOOLS DLLs.
4.) Do not click the preview button, the attachment will not show up when you post it.
 
If you do not wish to post your file(s) on the forum since they are publically viewable, please send an email to support@leadtools.com and make sure that you include a link to this forum post.

Greg Ross
LEADTOOLS Technical Support
   Report 
  03-05-2008, 14:50
SureshMittapalli is not online. Last active: 2/29/2008 4:43:32 PM SureshMittapalli

Top 100 Posts
Joined on 02-29-2008
Posts 22
Re: FaxG4 to RasPdf inverts colors
Reply Quote

Hi Greg,

 

Thanks for your mail, but you said "Using the ColorResolutionCommand to reverse the palette before calling CreateGdiPlusGraphics() might do the trick." Could you please tell me how to reverse the palette? 

 

It would be greta if you can give some piece of code to do this? Because it takes to see your reply oneday in mean time we loose time. When you give solution, it would be really helpful if you put some piece of code.

Hope you will undersatnd.

 

Thanks,

Suresh


   Report 
  03-06-2008, 9:14
GregR is not online. Last active: 10/10/2008 11:46:18 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,621
Re: FaxG4 to RasPdf inverts colors
Reply Quote
I forgot that in the .NET interface you can use SetPalette and do not need to use ColorResolution like you would in the C++ CLIB interface.  Here's a much simpler way to reverse the palette of a bitonal image.


RasterImage img1;
img1 = codecs.Load(@"C:\Program Files\LEAD Technologies, Inc\LEADTOOLS 15\Images\barcode1.tif");
RasterColor[] img1Palette = img1.GetPalette();
RasterColor[] reversedPalette = new RasterColor[2] {img1Palette[1], img1Palette[0]};
img1.SetPalette(reversedPalette, 0, reversedPalette.Length);


Greg Ross
LEADTOOLS Technical Support
   Report 
  03-07-2008, 9:59
SureshMittapalli is not online. Last active: 2/29/2008 4:43:32 PM SureshMittapalli

Top 100 Posts
Joined on 02-29-2008
Posts 22
Re: FaxG4 to RasPdf inverts colors
Reply Quote

Hi,

 

When tried twith the code you have given, its giving object reference not set tio an instance error when it is calling getpallette method.

 

Can you look into this? Here is my code:

  stream = new MemoryStream();
                RasterCodecs.Startup();
                RasterImageFormat imgFormat = GetRasFormatType(inputFile);
                rasCodecs = new RasterCodecs();
                RasterSupport.Unlock(RasterSupportType.PdfRead, pdfReadKey); //unlock PDF_READ
                RasterSupport.Unlock(RasterSupportType.PdfSave, pdfSaveKey); //unlock PDF_SAVE

             
                rasImage = rasCodecs.Load(inputFile); //Load input file

                for (int pageIndex = 1; pageIndex <= rasImage.PageCount; pageIndex++)
                {
                    rasImage.Page = pageIndex;
                    // Draw text on PDF.
                    container = rasImage.CreateGdiPlusGraphics();
                    container.Graphics.SmoothingMode = SmoothingMode.None;
                    container.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    Brush brush = new LinearGradientBrush(Point.Empty, new Point(200, 200), Color.Black, Color.Black);
                    Font textFont = new Font(FontFamily.GenericSansSerif, 15);
                    PointF point = new PointF(100, rasImage.Height - 80);
                    container.Graphics.DrawString("Generated By EIP Document Viewer at " + DateTime.Now.ToString(), textFont, brush, point);
               

                    RasterColor[] img1Palette = rasImage.GetPalette();
                    RasterColor[] reversedPalette = new RasterColor[2] { img1Palette[1], img1Palette[0] };
                    rasImage.SetPalette(reversedPalette, 0, reversedPalette.Length);

                }

                // Save the generated pdf
                rasCodecs.Save(rasImage, stream, imgFormat, 0, 1, -1, 1, CodecsSavePageMode.Overwrite);

 

Thanks,

Suresh

 


   Report 
  03-10-2008, 8:17
GregR is not online. Last active: 10/10/2008 11:46:18 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,621
Re: FaxG4 to RasPdf inverts colors
Reply Quote
This happening because CreateGdiPlusGraphics() must convert the image to a GDI+ compatible format.  When I tested it the image is getting converted to 24bpp, which doesn't have a palette.  Therefore GetPalette is returning null.  You'll need to convert the image back to 1bpp after writing the text onto it with the ColorResolutionCommand:


ColorResolutionCommand cmd = new ColorResolutionCommand();
cmd.BitsPerPixel = 1;
cmd.Mode = ColorResolutionCommandMode.InPlace;
cmd.Run(rasImage);


Then the palette reversal should work fine.  If you continue to have problems, please send a small sample project (NOT your entire application) that isolates your problem so i can try to reproduce it here.  Also make sure that you send an image that's giving you this problem because I couldn't reproduce the problem with any images I have here.



Greg Ross
LEADTOOLS Technical Support
   Report 
Post
LEAD Support Fo... » Developer » File Formats » Re: FaxG4 to RasPdf inverts colors

Powered by Community Server, by Telligent Systems