-->

How to add Watermark Image (Logo) to an image dynamically while uploading in ASP.NET.

Introduction

In this post I am explain how to add Watermark Image (logo) to an image dynamically while uploading in ASP.NET.

Steps :

Step-1 : Create New Project

Go to File > New > Project > Select asp.net web forms application > Entry Application Name > Click OK.

Step-2: Add Web Page and Design for Upload Image with Watermark Image (logo).

Go to Solution Explorer > Right Click on Project under solution explorer > Add > New item > Select Web Form using Master Page under web > Enter Name > > Select Master Page>Add.

HTML Code
  1. <h3>Upload Image with Watermark Image(Logo)</h3>
  2. <table>
  3. <tr>
  4. <td>Select Image : </td>
  5. <td>
  6. <asp:FileUpload ID="FU1" runat="server" /></td>
  7. </tr>
  8. <tr>
  9. <td>Watermark Logo : </td>
  10. <td>
  11. <asp:FileUpload ID="FULogo" runat="server" /></td>
  12. </tr>
  13. <tr>
  14. <td></td>
  15. <td>
  16. <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /></td>
  17. </tr>
  18. <tr>
  19. <td align="center" colspan="2">
  20. <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label>
  21. </td>
  22. </tr>
  23. </table>
  24. <asp:Image ID="Image1" runat="server" />

Step-3: Add a Folder for Save uploaded Images.

Go to Solution Explorer > Right Click on Project under solution explorer > Add > New Folder > Enter Name.

Step-4: Write code for Upload Image with Watermark Image.

Write below code into button click event for Upload Image with Watermark Image.

  1. protected void btnSave_Click(object sender, EventArgs e)
  2. {
  3. // HERE we will upload image with watermark LOGO
  4. string fileName = Guid.NewGuid() + Path.GetExtension(FU1.FileName);
  5. Image upImage = Image.FromStream(FU1.PostedFile.InputStream);
  6. Image logoImage = Image.FromStream(FULogo.PostedFile.InputStream);
  7. using (Graphics g = Graphics.FromImage(upImage))
  8. {
  9. g.DrawImage(logoImage, new Point(upImage.Width - logoImage.Width - 10, 10));
  10. upImage.Save(Path.Combine(Server.MapPath("~/UploadFiles"), fileName));
  11. Image1.ImageUrl = "~/UploadFiles" + "//" + fileName;
  12. }
  13. }

STEP-5: Run Application

Run Application and Get result in your browser.
Thank You



Related Post:


Hello ! My name is Sourav Mondal. I am a software developer working in Microsoft .NET technologies since 2010.

I like to share my working experience, research and knowledge through my site.

I love developing applications in Microsoft Technologies including Asp.Net webforms, mvc, winforms, c#.net, sql server, entity framework, Ajax, Jquery, web api, web service and more.

Related Posts: