Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys and Gals ....

I am using FreeImage to manipulate images that come through a fax system. The recieved images are being inverted (black to white) when they are saved. So therefore I need assistance in inverting the images that were inverted. The code below demontrates my objective. Any help would be appreciated. Thanks in advance.

C#
private void listViewPageViewer_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (pan != null)
                    pan.Dispose();

                if (listViewPageViewer.SelectedItems.Count == 0)
                {
                    return;
                }

                //int i = listViewPageViewer.SelectedItems[0].Index;
                int i = Convert.ToInt32(listViewPageViewer.SelectedItems[0].Name);

                savedImage = SourcePath + "Page_" + (i + 1).ToString() + ".tif";

                if (!File.Exists(savedImage))
                {
                    try
                    {
                        GlobalVariables.ImagePath = savedImage;
                        FIMULTIBITMAP dib = FreeImage.OpenMultiBitmapEx(strDocumentPath);
                        FIBITMAP page = FreeImage.LockPage(dib, i);
                        Image temp = FreeImage.GetBitmap(page);
                        


                       // I need to invert the image here before I save it to file


                        temp.Save(savedImage);
                        temp.Dispose();
                        temp = null;
                        pan = Image.FromFile(savedImage);
                        FreeImage.UnlockPage(dib, page, false);
                        PanBox.Image = pan;

                        FreeImage.CloseMultiBitmapEx(ref dib);

                        pan = Image.FromFile(savedImage);
                        PanBox.Image = pan;

                        originalImageHeight = pan.Height;
                        originalImageWidth = pan.Width;
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
Posted

Try:
FreeImage.Invert(temp);
 
Share this answer
 
Comments
Rico_ 17-Apr-12 2:55am    
Hi , thanks for your responce. I have tried that and got the error below. Im looking for another way around this.

Error 5 The best overloaded method match for 'FreeImageAPI.FreeImage.Invert(FreeImageAPI.FIBITMAP)' has some invalid arguments C:\DocSplitCurrent\DocSplitNew\PageViewer.cs 1196 25 DocSplitNew
Hi , I have found a solution on the net using GDI+, it seems to work for now, so i guess I am going to stick to this solution for now or until something else is needed.
Thanks for your help guys.

C#
if (temp.PixelFormat == PixelFormat.Format1bppIndexed)
    {
       Image img = temp;
       Bitmap bmpInverted = new Bitmap(img.Width, img.Height);
       ImageAttributes ia = new ImageAttributes();
       ColorMatrix cmPicture = new ColorMatrix(new float[][]
               {
                  new float[] {-1, 0, 0, 0, 0},
                  new float[] {0, -1, 0, 0, 0},
                  new float[] {0, 0, -1, 0, 0},
                  new float[] {0, 0, 0, 1, 0},
                  new float[] {1, 1, 1, 0, 1}
               });


        ia.SetColorMatrix(cmPicture);
        Graphics g = Graphics.FromImage(bmpInverted);
        g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
        g.Dispose();

        temp.Save(savedImage); 
        img.Dispose();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900