Thursday, September 24, 2009

Gdi+ in Asp .Net Code Snippets

This blog is the continuation of Gdi+ Code Snippets
and Gdi+ Brushes Code Snippets

using System.Drawing.Imaging;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Pen p = new Pen(Color.Yellow );
g.DrawLine(p, 5, 50, 50, 5);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
}
}

Custom Font

using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(200, 200);
Graphics g = Graphics.FromImage(bmp);

Font f = new Font(FontFamily.GenericSerif, 20, FontStyle.Bold ^ FontStyle.Italic );

g.DrawString("Shalvin.com", f, Brushes.White, 50, 50);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
}

Drawing a Pie Chart

using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Bitmap bmp = new Bitmap(200, 200);
        
        Rectangle r = new Rectangle(0, 0, 200, 200);
        
        Graphics g = Graphics.FromImage(bmp);
        g.SmoothingMode = SmoothingMode.AntiAlias;

        g.FillRectangle(Brushes.White, r);

        //25%
        g.FillPie(Brushes.LightBlue, r, 0, 90);

        //50%
        g.FillPie(Brushes.LightGreen, r, 90, 180);
        
        //25%
        g.FillPie(Brushes.LightGray, r, 270, 90);

        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

    }
}


Pie Chart Asp .Net Gdi+

No comments:

Post a Comment