NetImageLibrary icon indicating copy to clipboard operation
NetImageLibrary copied to clipboard

Unsharpmask

Open Darksilencer opened this issue 10 years ago • 5 comments
trafficstars

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

Darksilencer avatar Dec 21 '14 21:12 Darksilencer

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!

fschultz avatar Dec 22 '14 10:12 fschultz

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

Darksilencer avatar Dec 22 '14 15:12 Darksilencer

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

Darksilencer avatar Dec 22 '14 15:12 Darksilencer

Glad to hear it's working :)

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

fschultz avatar Dec 22 '14 16:12 fschultz

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

Darksilencer avatar Dec 22 '14 16:12 Darksilencer