Proxy > Gmail Facebook Yahoo!

Add watermark to an image using C#




Below is the sample. I call it ShowImage.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
 
<script runat="server">
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["image"] == null) return;
        string WatermarkImg = 
              Server.MapPath(@"images\watermark.png");
        string CarImg = 
              Server.MapPath(Request.QueryString["image"]);
 
        Bitmap bmp = new Bitmap(CarImg);
 
        Graphics g = Graphics.FromImage(bmp);
 
        g.SmoothingMode = SmoothingMode.HighQuality;
 
        Bitmap bmpWM = (Bitmap)Bitmap.FromFile(WatermarkImg);
 
        g.DrawImage(bmpWM, new Point(bmp.Width-bmpWM.Width,
                    bmp.Height-bmpWM.Height) );
 
        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
        bmp.Dispose();
        bmpWM.Dispose();
        g.Flush();
    }
</script>
You can call this using:
<asp:Image ID="Image4" runat="server" ImageUrl
     ="~/ShowImage.aspx?image=images\cadillac_thumb.jpg" />
<img src="ShowImage.aspx?image=images\pagani.jpg" />


Responses

0 Respones to "Add watermark to an image using C#"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar