Asmageddon Prince Posted December 1, 2007 Share Posted December 1, 2007 Please help me, how to draw anything in C#. I wasted three days trying to do anything like that. First I tried creating System.Drawing.Bitmap, but I don`t know how to display it on form, I only managed to create a drawing and saved it, but it wasn`t visible on screen. Second I tried System.Drawing.Graphics, but I always get error: "Object reference not set to an instance of an object" I tried .CreateObjRef, but don`t know how to set type. Third I tried creating .BMP resource, setting it as image for PictureBox, but when I try to modify it I always get error: "SetPixel is not supported for images with indexed pixel formats." Please, I beg you! Help me!!! The Asmageddon is coming. You better prepare... or you won`t survive Link to comment Share on other sites More sharing options...
Andrew D Posted December 1, 2007 Share Posted December 1, 2007 Please help me, how to draw anything in C#.I wasted three days trying to do anything like that. First I tried creating System.Drawing.Bitmap, but I don`t know how to display it on form, I only managed to create a drawing and saved it, but it wasn`t visible on screen. Second I tried System.Drawing.Graphics, but I always get error: "Object reference not set to an instance of an object" I tried .CreateObjRef, but don`t know how to set type. Third I tried creating .BMP resource, setting it as image for PictureBox, but when I try to modify it I always get error: "SetPixel is not supported for images with indexed pixel formats." Please, I beg you! Help me!!! You don't need to "draw" anything really. Your trying to create a UI for a PDN plug-in, right? If so, either use the new "IndirectUI" system or the design tools in it. Link to comment Share on other sites More sharing options...
Bob Posted December 1, 2007 Share Posted December 1, 2007 What do you want to draw, and where do you want to draw it? No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio Link to comment Share on other sites More sharing options...
Asmageddon Prince Posted December 1, 2007 Author Share Posted December 1, 2007 What do you want to draw, and where do you want to draw it? Anything, anywhere, just draw something, like Line,dot,circle or rectangle.And anywhere on picture, on window, or anywhere, just draw something! About UI, I know how to create it, I`m not a moron, I`m just very very frustrated. EDIT:I want to create graphic program, where you can draw something like in Paint.NET The Asmageddon is coming. You better prepare... or you won`t survive Link to comment Share on other sites More sharing options...
MadJik Posted December 1, 2007 Share Posted December 1, 2007 You should find a forum dedicated to C#... BTWn this is a Codelab I've used for the early version of the spirograph, in which you'll find a good example (IMO) of the code to draw polygones with/for Paint.net: int Amount1=5; //[3,25]Quantity of angles int Amount2=4; //[2,99]Density int Amount3=99; //[2,99]Depth void Render(Surface dst, Surface src, Rectangle rect) { // Parameters int QtAng = Amount1; int AmDens = Amount2; int AmDeep = 100 - Amount3; int AmZoom = 98; int MaxIter = 2000; // Security limit for the while loop! PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); long MaxiX = (long)(selection.Right - selection.Left); long MaxiY = (long)(selection.Bottom - selection.Top); long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left); long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top); int Radius = (int)(AmZoom * Math.Min(MaxiX, MaxiY) / 200); ColorBgra PrimColor = (ColorBgra)EnvironmentParameters.PrimaryColor; ColorBgra BackColor = (ColorBgra)EnvironmentParameters.SecondaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; SolidBrush Brush1 = new SolidBrush(Color.FromArgb(PrimColor.A, PrimColor.R, PrimColor.G, PrimColor.); SolidBrush Brush2 = new SolidBrush(Color.FromArgb(BackColor.A, BackColor.R, BackColor.G, BackColor.); Pen Pen1 = new Pen(Brush1, BrushWidth); Pen Pen2 = new Pen(Brush2, BrushWidth); bool Alt = true; // Calculate the X,Y coords of the angles double[] sx = new double[1 + QtAng]; double[] sy = new double[1 + QtAng]; for (int i = 0; i < QtAng; i++) { sx[i] = CenterX + Radius * Math.Cos(i * 2 * Math.PI / QtAng); sy[i] = CenterY + Radius * Math.Sin(2 * Math.PI * i / QtAng); } // Last coords = first coords to close the polygon. sx[QtAng] = sx[0]; sy[QtAng] = sy[0]; // Copy existing image (source) to destination for (int y = rect.Top; y < rect.Bottom; ++y) for (int x = rect.Left; x < rect.Right; ++x) dst[x, y] = src[x, y]; Graphics g = new RenderArgs(dst).Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.Clip = new Region(rect); int x1, y1, x2, y2; while ((MaxIter>0) && (d(sx[0], sy[0], CenterX, CenterY) > Radius * AmDeep / 100)) { MaxIter--; x1 = (int)sx[0]; y1 = (int)sy[0]; Point[] Piece = new Point[1 + QtAng]; for (int i = 0; i < 1 + QtAng; i++) { x2 = (int)sx[i]; y2 = (int)sy[i]; //g.DrawLine(Pen1, x1, y1, x2, y2); Piece[i] = new Point(x2,y2); x1 = x2; y1 = y2; } if (Alt) {g.FillPolygon(Brush1, Piece);} else {g.FillPolygon(Brush2, Piece);} Alt = !Alt; // boucle de dessin effectuer for (int i = 0; i < QtAng; i++) { sx[i] = sx[i] + (sx[1 + i] - sx[i]) / AmDens; sy[i] = sy[i] + (sy[1 + i] - sy[i]) / AmDens; } sx[QtAng] = sx[0]; sy[QtAng] = sy[0]; } } double d(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x1 - x2, 2.0) + Math.Pow(y1 - y2, 2.0)); } Don't forget, help is your friend, it is true also for the C# code... My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Asmageddon Prince Posted December 2, 2007 Author Share Posted December 2, 2007 I don`t want to create plugin for Paint.NET, I wan`t to create a simple graphic program myself! I made a game using Built-in Components and writing function, I know how to create classes, I created a component, but I don`t know how to make it visible!And I didn`t found a way to acces code of ready components. I made many plugins for Paint.NET, but I want to create something that will draw something on the form, or other component. The Asmageddon is coming. You better prepare... or you won`t survive Link to comment Share on other sites More sharing options...
Rick Brewster Posted December 2, 2007 Share Posted December 2, 2007 This is a forum for Paint.NET, not for C# or graphics coding in general. And you should know by now that having "HELP!" in your topic is frowned upon (to pit it mildly). It's kind of a pet peeve of mine. Thread Closed 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