Quantcast
Channel: Ghostscript.NET
Viewing all articles
Browse latest Browse all 393

New Post: Invert Image colors

$
0
0
Hi Josip,

Thanks for helping me out. I was a little confused, but its working now. I noticed the DisplaySize event is called twice when loading a document, and DisplayUpdate can be called more than once, and in the source code you call pbPage.Invalidate(); and pbPage.Update() in both DisplayUpdate and DisplayPage handler. I only call pbPage.Invalidate(); in DisplayUpdate. (less flashing now)

I changed this:
pbPage.Image = this.Transform(pbPage.Image as Bitmap);
to this
pbPage.Image = this.Transform(e.Image as Bitmap);
because the image was converted back to original when going to the next page, and the page was not going to the next one.

and i keep track if image is converted or not.
this the result:
    void _viewer_DisplaySize(object sender, GhostscriptViewerViewEventArgs e)
    {
        pbPage.Image = e.Image;
        System.Diagnostics.Debug.Write("displaySize...." + "\n");
    }

    void _viewer_DisplayUpdate(object sender, GhostscriptViewerViewEventArgs e)
    {
        pbPage.Invalidate();
        System.Diagnostics.Debug.Write("displayUpdate...." + "\n");
    }

    void _viewer_DisplayPage(object sender, GhostscriptViewerViewEventArgs e)
    {
        if (_isInverted == true)
        {
            pbPage.Image = this.InvertBitmap(e.Image);
        }

        System.Diagnostics.Debug.Write("displayPage...." + "\n");
        tbPageNumber.Text = _viewer.CurrentPageNumber.ToString();
        tbTotalPages.Text = " / " + _viewer.LastPageNumber.ToString();
    }

    public Bitmap InvertBitmap(Image img)
    {
        Bitmap bm = new Bitmap(img.Width, img.Height);
        Graphics g = Graphics.FromImage(bm);
        ColorMatrix cm = 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}
        });
        ImageAttributes ia = new ImageAttributes();
        ia.SetColorMatrix(cm);
        g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
        g.Dispose();

        return bm;
    }
Thanks again,
regards, Sil

Viewing all articles
Browse latest Browse all 393

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>