Dynamically add both watermark image and upload image in asp.net c#
As we previously learn about how to add watermarktext on upload image and how to add watermark image on upload image when logo(image) is fixed but now we learn about how we can add watermark image (logo)
and upload image according to our requirement means we can add watermark image according to our needs.
Suppose we have 3 logo (water mark image) and we
upload according to our needs then this code defiantly will help you.
Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="watermarkonuploadimage.aspx.cs" Inherits="watermarkonuploadimage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> watermark-example
with neerajcodesolutions</title>
</head>
<body>
<form id="form1" runat="server">
<fieldset style="width: 450px">
<legend>Add
Watermark image(logo) on Upload Image Dyanmically</legend>
<label>Upload
Image</label>
<asp:FileUpload ID="fileuploadimage" runat="server" />
<br />
<br />
<label>Upload
logo</label>
<asp:FileUpload ID="fileuploadlogo" runat="server" />
<br />
<br />
<asp:Button ID="btnupload" Text="Upload" runat="server" OnClick="btnupload_Click" />
</fieldset>
<fieldset style="width:
350px">
<legend>Out-Put
</legend>
<asp:Image ID="imgoutput" runat="server" Width="350px" />
</fieldset>
</form>
</body>
</html>
Code behind(C#):-
using
System;
using
System.Collections.Generic;
using
System.Drawing;
using
System.Drawing.Imaging;
using
System.IO;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
public partial class watermarkonuploadimage :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
btnupload_Click(object sender, EventArgs e)
{
try
{
string
fileName = Guid.NewGuid() + Path.GetExtension(fileuploadimage.FileName);
Image
upImage = Image.FromStream(fileuploadimage.PostedFile.InputStream);
Image
logoImage = Image.FromStream(fileuploadlogo.PostedFile.InputStream);
using (Graphics
objgraphics = Graphics.FromImage(upImage))
{
objgraphics.DrawImage(logoImage, new Point(upImage.Width
- logoImage.Width - 40, 40));
upImage.Save(Path.Combine(Server.MapPath("~/images"),
fileName));
imgoutput.ImageUrl = "~/images" + "//" +
fileName;
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
Out-Put:-
Dynamically add both watermark image and upload image in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
11:25:00 PM
Rating:
No comments: