lopper Posted June 7, 2017 Share Posted June 7, 2017 Hey i know this question is kinda off but bare with me. Does anybody know how paint.net adds a sharpness effect to a image through code. it would be nice to mabe give a example code on how it does this. Or any kind of code to add a sharpness effect to a image it has to be in c# just curious i know the color option to a image but not a effect like sharpness. Again a off question but i would like to find out this. Link to comment Share on other sites More sharing options...
Rick Brewster Posted June 7, 2017 Share Posted June 7, 2017 just search google The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
lopper Posted June 7, 2017 Author Share Posted June 7, 2017 Um i already have searched google that's why i am here to ask this directly to the community of paint.net. so still i need some advice on my question. Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted June 7, 2017 Share Posted June 7, 2017 The code is not available. It belongs to Rick. It's not something he hands out on request. ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
BoltBait Posted June 7, 2017 Share Posted June 7, 2017 19 hours ago, lopper said: Does anybody know how paint.net adds a sharpness effect to a image through code. I don't know how paint.net does it, but if you are simply interested in an algorithm for sharpening a photograph, here's one: // Author: BoltBait // Submenu: Photo // Name: Sharpen (unsharp mask) // URL: http://www.BoltBait.com/pdn #region UICode IntSliderControl Amount1 = 100; // [0,200] Sharpen #endregion unsafe void Render(Surface dst, Surface src, Rectangle rect) { // Setup for calling the Gaussian Blur (radius = 1) function GaussianBlurEffect blurEffect = new GaussianBlurEffect(); PropertyCollection bProps = blurEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken bParameters = new PropertyBasedEffectConfigToken(bProps); bParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, 1); blurEffect.SetRenderInfo(bParameters, new RenderArgs(dst), new RenderArgs(src)); blurEffect.Render(new Rectangle[1] {rect},0,1); // Now in the main render loop, the dst canvas has a blurred version of the src canvas for (int y = rect.Top; y < rect.Bottom; y++) { ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y); ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y); for (int x = rect.Left; x < rect.Right; x++) { ColorBgra AdjustmentPixel = *dstPtr; // blurred pixel ColorBgra SourcePixel = *srcPtr; // original pixel // Sharpen (unsharp mask) double NewR = (double)SourcePixel.R + ((double)SourcePixel.R - (double)AdjustmentPixel.R) * (double)Amount1 / 100.0; double NewG = (double)SourcePixel.G + ((double)SourcePixel.G - (double)AdjustmentPixel.G) * (double)Amount1 / 100.0; double NewB = (double)SourcePixel.B + ((double)SourcePixel.B - (double)AdjustmentPixel.B) * (double)Amount1 / 100.0; AdjustmentPixel.R = Int32Util.ClampToByte((int)NewR); AdjustmentPixel.G = Int32Util.ClampToByte((int)NewG); AdjustmentPixel.B = Int32Util.ClampToByte((int)NewB); *dstPtr = AdjustmentPixel; srcPtr++; dstPtr++; } } } If you have my plugin pack installed, this is the same sharpen method my Photo > Landscape plugin uses. I just isolated the sharpen code and posted it above. If you need help understanding what is happening, just ask and I (or someone else) will explain it to you. Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Rick Brewster Posted June 12, 2017 Share Posted June 12, 2017 What I meant by "just google it" is that sharpening an image is a well known algorithm in Computer Science and Graphics. Paint.NET isn't really doing anything novel here, aside from maybe some optimizations. So you'll just have better success if you broaden the scope of your search. You can also use something like Reflector or ILSpy to take a peek at a disassembly of Paint.NET's DLLs. You'd want to look at what's in PaintDotNet.Effects.dll. 1 The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Gregitis Posted February 11, 2023 Share Posted February 11, 2023 On 6/7/2017 at 12:23 AM, Rick Brewster said: just search google I Updated my Paint.net to 5.0.1. now the sharpness feature seems not to be working. Link to comment Share on other sites More sharing options...
BoltBait Posted February 11, 2023 Share Posted February 11, 2023 2 hours ago, Gregitis said: I Updated my Paint.net to 5.0.1. now the sharpness feature seems not to be working. Sharpen was rewritten for Paint.NET v5. If you are looking for the classic sharpen effect, just install my plugin pack. Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
Rick Brewster Posted February 11, 2023 Share Posted February 11, 2023 This thread is very old and your question is a new, unrelated one. Please just create a new post in the future. The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Recommended Posts