Results 1 to 3 of 3

Thread: [GDI+] demo

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    [GDI+] demo

    I've been doing a few graphics demo's in the VB.Net forum and since I'm moving over to C# it would be rude to neglect the C# forum

    I'd welcome any comments you might have.

    Just put a button on your form and hook it up to this sub then click it a few times...

    Code:
    		private void button1_Click(object sender, EventArgs e)
    {
    	Random _R = new Random();
    
    	//define a rectangle to base the gradient brush on
    	Rectangle r =new Rectangle(10, 10, 500, 500);
    	//create the brush
    	LinearGradientBrush lgb = new LinearGradientBrush(r, Color.Red, Color.Yellow, 45);
    	
    	//create a pen from the brush
    	Pen coolPen = new Pen(lgb, _R.Next(15, 50));
    
    	//make the pen have a multiple-nib effect and add a few other effects
    	coolPen.CompoundArray = new Single[]{0.0f, 0.3f, 0.4f, 0.7f, 0.85f, 1.0f};
    	//these effects are activated on a random basis
    	if(_R.NextDouble() < 0.5) coolPen.LineJoin = LineJoin.Round;
    	if (_R.NextDouble() < 0.5) coolPen.StartCap = LineCap.Round;
    	if (_R.NextDouble() < 0.5) coolPen.EndCap = LineCap.ArrowAnchor;
    	//customise dash pattern
    	if (_R.NextDouble() < 0.2) coolPen.DashPattern = new Single[] {1f, 0.2f, 2f, 0.2f, 1f, 2f, 0.5f, 1f};
    
    	//define the bezier control points
    	Point[] pts = new Point[] {	new Point(25,50), 
    									new Point(400,50),
    									new Point(500,200),
    									new Point(380,230), 
    									new Point(300,150), 
    									new Point(120,300), 
    									new Point(280,400)  };
    
    	//get a reference to the form's graphics object
    	Graphics gr = this.CreateGraphics();
    	
    	//clear the drawing area
    	gr.Clear(this.BackColor);
    	
    	//antialias the drawing
    	gr.SmoothingMode = SmoothingMode.AntiAlias;
    
    	//draw the effect
    	gr.DrawBeziers(coolPen, pts);
    
    	gr.Dispose();
    	lgb.Dispose();
    	coolPen.Dispose();
    
    }
    I didn't put this in the codebank because I'm not expert enough in C# yet (havent used it in a year, just getting back into the swing of things).
    Last edited by wossname; Jul 4th, 2005 at 03:47 AM.
    I don't live here any more.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: [GDI+] demo

    you noob
    you need to dispose your brushes and your graphics objects and you pens and your life
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [GDI+] demo

    That's true, forgot all about that. Not noob for long mate.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width