XLIVE99 Posted August 20 Share Posted August 20 This effect discards middle parts of the image to make it require less space. Main purpose of this effect is discard the unnecessary parts of the image to effectively use that image in sprite atlas. This way you can use the image with 9-sliced technique without any loss (such as used in Unity). I was tired of manually doing this over and over again (you have to modify most of the game assets published in the internet to pack tightly in sprite atlas). And it is time consuming to make all the border size's consistent. Since Paint.NET stores last used effect parameters, you can make every sprite consistent (Same size as the previous sprite) Preview How to use Download the plugin NineSlicer.zip Extract the zip file Install into Paint.NET (Either double clicking "Install_NineSlicer.bat" or place "NineSlicer.dll" in "Effects" folder, by default it should be located at "Program Files/paint.net/Effects") Open Paint.NET and go into Effects->Object->Nine Slicer Parameters Left: Left border size Left-Right Symmetry: If checked right border size will be equal to left border size Right: Right border size (You have to uncheck Left-Right Symmetry to change this parameter) Top: Top border size Top-Bottom Symmetry: If checked bottom border size will be equal to top border size Bottom: Bottom border size (You have to uncheck Top-Bottom Symmetry to change this parameter) Source Code License CC0 1.0 https://creativecommons.org/publicdomain/zero/1.0/deed.tr Spoiler #region UICode IntSliderControl BorderLeft = 16; // [1,256] Left CheckboxControl SymmetryX = true; // Left-Right Symmetry IntSliderControl BorderRight = 16; // [1,256] {!SymmetryX} Right IntSliderControl BorderTop = 16; // [1,256] Top CheckboxControl SymmetryY = true; // Top-Bottom Symmetry IntSliderControl BorderBottom = 16; // [1,256] {!SymmetryY} Bottom #endregion protected override void OnRender(IBitmapEffectOutput output) { using IEffectInputBitmap<ColorBgra32> sourceBitmap = Environment.GetSourceBitmapBgra32(); using IBitmapLock<ColorBgra32> sourceLock = sourceBitmap.Lock(new RectInt32(0, 0, sourceBitmap.Size)); RegionPtr<ColorBgra32> sourceRegion = sourceLock.AsRegionPtr(); RectInt32 outputBounds = output.Bounds; using IBitmapLock<ColorBgra32> outputLock = output.LockBgra32(); RegionPtr<ColorBgra32> outputSubRegion = outputLock.AsRegionPtr(); var outputRegion = outputSubRegion.OffsetView(-outputBounds.Location); // Delete any of these lines you don't need ColorBgra32 primaryColor = Environment.PrimaryColor; ColorBgra32 secondaryColor = Environment.SecondaryColor; var selection = Environment.Selection.RenderBounds; int selectionWidth = selection.Right - selection.Left; int selectionHeight = selection.Bottom - selection.Top; if(SymmetryX) BorderRight = BorderLeft; if(SymmetryY) BorderBottom = BorderTop; // Horizontal distance between borders int borderWidth = BorderLeft + BorderRight; int borderHeight = BorderTop + BorderBottom; int borderHorDistance = selectionWidth - borderWidth; int borderVerDistance = selectionHeight - borderHeight; if(borderHorDistance < 0) borderHorDistance = 0; if(borderVerDistance < 0) borderVerDistance = 0; // Loop through the output canvas tile for (int y = outputBounds.Top; y < outputBounds.Bottom; ++y) { if (IsCancelRequested) return; for (int x = outputBounds.Left; x < outputBounds.Right; ++x) { // Get your source pixel ColorBgra32 sourcePixel = sourceRegion[x,y]; if(y >= selection.Top && y < selection.Bottom && x >= selection.Left && x < selection.Right) { int offsetY = 0; int offsetX = 0; int yDiff = y - selection.Top; int xDiff = x - selection.Left; // Check if we are in border area if(yDiff < borderHeight && xDiff < borderWidth) { if(xDiff > BorderLeft) offsetX = borderHorDistance; if(yDiff > BorderTop) offsetY = borderVerDistance; sourcePixel = sourceRegion[x + offsetX, y + offsetY]; } else { sourcePixel = SrgbColors.Transparent; } } // Save your pixel to the output canvas outputRegion[x,y] = sourcePixel; } } } 5 Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted August 21 Share Posted August 21 Welcome to the forum @XLIVE99 This is an excellent write-up! I'm impressed ⭐⭐⭐ 1 Quote 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...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.