Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, August 22, 2007 8:56:30 AM(UTC)

Kevin B  
Kevin B

Groups: Registered
Posts: 14


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
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, August 24, 2007 5:14:30 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


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.

 
#3 Posted : Wednesday, December 19, 2007 8:43:11 AM(UTC)
gatorjoe

Groups: Registered
Posts: 2


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

 
#4 Posted : Friday, December 21, 2007 9:16:19 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


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.
 
#5 Posted : Tuesday, March 4, 2008 5:55:36 AM(UTC)
SureshMittapalli

Groups: Registered
Posts: 22


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);

}

 
#6 Posted : Wednesday, March 5, 2008 4:11:25 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


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.
 
#7 Posted : Wednesday, March 5, 2008 9:45:41 AM(UTC)
SureshMittapalli

Groups: Registered
Posts: 22


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

 
#8 Posted : Thursday, March 6, 2008 4:09:37 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


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);

 
#9 Posted : Friday, March 7, 2008 4:54:01 AM(UTC)
SureshMittapalli

Groups: Registered
Posts: 22


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

 

 
#10 Posted : Monday, March 10, 2008 3:12:17 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


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.


 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.180 seconds.