使用FreeImage.dll反转图像 [英] Invert Image using FreeImage.dll

查看:122
本文介绍了使用FreeImage.dll反转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Guys and Gals ....

我正在使用FreeImage处理通过传真系统传来的图像.保存时,接收到的图像将被反转(黑到白).因此,在反转反转的图像时,我需要帮助.下面的代码破坏了我的目标.任何帮助,将不胜感激.提前谢谢.

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.

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
            {
            }
        }

推荐答案

尝试:
FreeImage.Invert(temp);


我在网上找到了使用GDI +的解决方案,它似乎暂时可以正常工作,所以我想我暂时还是要坚持使用此解决方案,直到需要其他解决方案为止.
感谢您的帮助.

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.

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


这篇关于使用FreeImage.dll反转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆