fschultz / NetImageLibrary

Library to help with image handling such as resizing, cropping, applying filters (brightess, contrast, unsharpen mask, chroma key etc), watermarking, thumbnail creation, opening/saving files or streams and more.
http://kaliko.com/image-library/
Other
90 stars 27 forks source link

Unsharpmask #2

Open Darksilencer opened 9 years ago

Darksilencer commented 9 years ago
            MemoryStream memstream = new MemoryStream();

            bitmap2.Save(memstream, System.Drawing.Imaging.ImageFormat.Png);

            KalikoImage imgklk = new KalikoImage(memstream);

            imgklk.ApplyFilter(new UnsharpMaskFilter(150f, 100f, 200));

            imgklk.SavePng(memstream);

            Bitmap bitmap3 = new Bitmap(memstream);

This is my code for filtering my bitmap2 image.But when i use unsharp on imgklk,i feel filtering is aplied because there is noticeably time passing program to return back but im unable to see it on bitmap3,i mean there is no difference between bitmap 2 and bitmap 3.I hope you can help me:)

fschultz commented 9 years ago

When doing a second write to the memory stream it seems that it append the second image after the first one and when the image is retrieved to the bitmap object it's the first one that was written.

In order to fix this you need to create a new memory stream before saving the image the second time. (Depending on your image you might also want to lower the threshold value (third parameter of UnsharpMaskFilter) in order to see the effect):

        MemoryStream memstream = new MemoryStream();

        bitmap2.Save(memstream, System.Drawing.Imaging.ImageFormat.Png);

        KalikoImage imgklk = new KalikoImage(memstream);

        imgklk.ApplyFilter(new UnsharpMaskFilter(1.5f, 2f, 0));

        memstream = new MemoryStream();
        imgklk.SavePng(memstream);

        Bitmap bitmap3 = new Bitmap(memstream);

With this you should see a difference between the two images. Hope this helps!

Darksilencer commented 9 years ago

yes now it is working,Thank you! and thanks for library too:)

Darksilencer commented 9 years ago

Also i want to change my image to grayscale,is this possible with your library? i saw lots of color change method but didnt see rgb to grayscale

fschultz commented 9 years ago

Glad to hear it's working :)

The easiest way to make your image grayscale is to apply the DesaturationFilter: imgklk.ApplyFilter(new DesaturationFilter());

Darksilencer commented 9 years ago

Annnd grayscale is done too.Thank you very much:) But now there is a problem.When i use 3 things from kaliko library i get indexoutofrange exception: "System.IndexOutOfRangeException' occurred in Kaliko.ImageLibrary.dll"

When i use these things: imgklk.ApplyFilter(new DesaturationFilter()); imgklk.Resize(imgklk.Width * 2, imgklk.Height * 2); imgklk.ApplyFilter(new UnsharpMaskFilter(1.5f, 2f, 0));