dylanjosh Posted July 28, 2015 Share Posted July 28, 2015 Shouldn't this give me a grid with gaps of 50 pixels between the lines? However it gives nothing like that. #region UICode int Amount1=0; //[0,100]Slider 1 Description int Amount2=0; //[0,100]Slider 2 Description int Amount3=0; //[0,100]Slider 3 Description #endregion void Render(Surface dst, Surface src, Rectangle rect) { // Delete any of these lines you don't need Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); int CenterX = ((selection.Right - selection.Left) / 2)+selection.Left; int CenterY = ((selection.Bottom - selection.Top) / 2)+selection.Top; ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor; ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; ColorBgra CurrentPixel; for (int y = rect.Top; y < rect.Bottom; y += 50) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x += 50) { CurrentPixel = src[x,y]; // TODO: Add pixel processing code here // Access RGBA values this way, for example: CurrentPixel.R = (byte)PrimaryColor.R; CurrentPixel.G = (byte)PrimaryColor.G; CurrentPixel.B = (byte)PrimaryColor.B; CurrentPixel.A = (byte)PrimaryColor.A; dst[x,y] = CurrentPixel; } } } Sometimes I get the whole image black, some times I get only vertical lines, sometimes I get horizontal likes with gap only 1 pixel. What gives? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted July 28, 2015 Share Posted July 28, 2015 You can't just increment 50 on the X and Y loops. Review this: http://boltbait.com/pdn/CodeLab/help/overview.asp Then, look over this thread (all the pages) for some code: http://forums.getpaint.net/index.php?/topic/1964- Quote Download: BoltBait's Plugin Pack | CodeLab | and a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted July 28, 2015 Share Posted July 28, 2015 (edited) dylanjosh, set all the destination pixels, but choose the pixel color based of its position. I'm not certain what you intend to do, but for the sake of demonstration, I'll make a white background with black lines in each direction spaced 50 apart (49 pixels in between). If I wanted the grid superimposed on the original image, instead of CurrentPixel = ColorBgra.White, I'd use CurrentPixel = src[x, y]. Each call to the render code isn't writing the whole destination window at one time; it's writing a portion, referred to as a Rectangle of Interest. Notice the loop bounds for y aren't 0 to dst.Height, they're rect.Top to rect.Bottom. So you can't step by 50, since the starting point can be anywhere within the destination window. Read BoltBait's CodeLab help pages carefully. They describe most everything you'll need to know to write CodeLab plugins. I'll also mention that, ignoring the other problems, what you're doing would only put pixel dots every 50 pixels rather than pixel lines. Assuming you want lines, every y row of pixels contains some grid pixels, so you can't skip over 50 y rows. (To change my code to draw dots instead of lines, replace the || OR with && AND.) (If I were actually writing code to do this, I might do it slightly differently, but this version is straightforward.) ColorBgra CurrentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { // See if it's a grid pixel. if ((x % 50 == 0) || (y % 50 == 0)) CurrentPixel = ColorBgra.Black; // Grid pixel. else CurrentPixel = ColorBgra.White; // Not a grid pixel. dst[x, y] = CurrentPixel; } } Edited July 28, 2015 by MJW 1 Quote Link to comment Share on other sites More sharing options...
Red ochre Posted July 28, 2015 Share Posted July 28, 2015 Another way is to copy all of the source canvas to the destination in one go, then use the 'G.D.I.+' library to 'draw' the lines.Example codelab code link below. (Do thoroughly read BoltBait's tutorials first) http://forums.getpaint.net/index.php?/topic/31885-request-tablegrid/ Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings Link to comment Share on other sites More sharing options...
ReMake Posted July 28, 2015 Share Posted July 28, 2015 Hello, dylanjosh and welcome to the forum. Maybe this tutorial will help you to create a grid plugin which you need. Quote 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.