Home > ASP.Net > Generate Curved Image

Generate Curved Image


Hi

try this example:-

Add new web page and add FileUpload and Button control

and in code behind:-

protected void Button1_Click(object sender, EventArgs e)
    {
        //string path = Server.MapPath("~/Images/602869611.jpg");
        string path = FileUpload1.PostedFile.FileName;

        int roundedDia = 50;
        using (System.Drawing.Image imgin = System.Drawing.Image.FromFile(path))
        {
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width, imgin.Height);
            Graphics g = Graphics.FromImage(bitmap);
            g.Clear(Color.White);
            Brush brush = new System.Drawing.TextureBrush(imgin);
            FillRoundedRectangle(g, new Rectangle(0, 0, imgin.Width, imgin.Height), roundedDia, brush);
            // done with drawing dispose graphics object.
            g.Dispose();
            // Stream Image to client.
            Response.Clear();
            Response.ContentType = "image/pjpeg";
           // bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            Response.End();
            // dispose bitmap object.
            bitmap.Dispose();
        
        }
    }

    public static void FillRoundedRectangle(Graphics g, Rectangle r, int d, Brush b)
    {
        // anti alias distorts fill so remove it.
        System.Drawing.Drawing2D.SmoothingMode mode = g.SmoothingMode;
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
        g.FillPie(b, r.X, r.Y, d, d, 180, 90);
        g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90);
        g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90);
        g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
        g.FillRectangle(b, r.X + d / 2, r.Y, r.Width - d, d / 2);
        g.FillRectangle(b, r.X, r.Y + d / 2, r.Width, r.Height - d);
        g.FillRectangle(b, r.X + d / 2, r.Y + r.Height - d / 2, r.Width - d, d / 2);
        g.SmoothingMode = mode;
    }

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: