toe_head2001 Posted August 23, 2015 Share Posted August 23, 2015 I'm try to get a my (smaller) 'img' Surface lined up with the selection of the canvas. Say I have a selection start at point (50,50), and run this code: ... img = Surface.CopyFromBitmap(myBitmap); void Render(Surface dst, Surface src, Rectangle rect) { for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { dst[x,y] = img.GetBilinearSample(x - rect.Left,y - rect.Top); } } Substracting from 'rect.Left' on 'x' makes it start from 0 as expected, but subtracting from 'rect.Top' on y doesn't seem to work. Can you explain why that is? Quote (June 9th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
midora Posted August 23, 2015 Share Posted August 23, 2015 Missing the check for width and height of the small img surface. Maybe use the clamped variant of GetBilinearSample. Quote Link to comment Share on other sites More sharing options...
MJW Posted August 23, 2015 Share Posted August 23, 2015 (edited) rect is the ROI, not the selection. It works for X because for rectangular selections, the X origins of the ROIs coincide with the X origin of the selection. Get the selection (as done in CodeLab) by: Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); Then: dst[x,y] = img.GetBilinearSample(x - selection.Left,y - selection.Top); Edited August 23, 2015 by MJW 1 Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 23, 2015 Author Share Posted August 23, 2015 rect is the ROI, not the selection. It works for X because for rectangular selections, the X origins of the ROIs coincide with the X origin of the selection. Thanks for explaining this! This whole time I thought the ROI was based on the selection. I never bothered reading that part of the code to understand what was going on. Quote (June 9th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Rick Brewster Posted August 23, 2015 Share Posted August 23, 2015 The ROI is based on the selection. But each rectangle describes only a part of the ROI. 1 Quote 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...
TechnoRobbo Posted August 24, 2015 Share Posted August 24, 2015 this may gave you some insight - run this, don't even build it , just paste it in CodeLab. Then try a selection. // Name: // Submenu: // Author: // Title: // Desc: // Keywords: // URL: // Help: #region UICode #endregion Random rndm = new Random((int)Guid.NewGuid().GetHashCode()); void Render(Surface dst, Surface src, Rectangle rect) { ColorBgra CurrentPixel = ColorBgra.FromBgr( (byte)rndm.Next(256), (byte)rndm.Next(256),(byte)rndm.Next(256)); for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { dst[x,y] = CurrentPixel; } } } 1 Quote Go out there and be amazing. Have Fun, TRSome Pretty Pictures Some Cool Plugins Link to comment Share on other sites More sharing options...
BoltBait Posted August 24, 2015 Share Posted August 24, 2015 Or, you could just read this page: http://boltbait.com/pdn/CodeLab/help/overview.asp 1 Quote Download: BoltBait's Plugin Pack | CodeLab | and a Computer Dominos Game Link to comment Share on other sites More sharing options...
toe_head2001 Posted August 24, 2015 Author Share Posted August 24, 2015 Or, you could just read this page: http://boltbait.com/pdn/CodeLab/help/overview.asp Indeed, it's been much to long since I read that, and apparently I didn't fully understand it that first time. Thanks everyone. Quote (June 9th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab 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.