with reference to your article
I have uploaded an image and want to write water mark user's their own choice.
Now when i wrote inside textbox and tried to download it is showing me message that Failed-Network error.
For that purpose i wrote the following code.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<br />
<script language="javascript" type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#filePhoto").change(function () {
readURL(this);
});
</script>
<div class="panel panel-info">
<div class="panel-body">
<asp:FileUpload ID="FilePhoto" runat="server" CssClass="fileupload" onchange="readURL(this)" /><br />
<img id="blah" src="Images/imge.png" alt="Live Preview" class="img-thumbnail" width="300"
height="400" />
<br />
<div class="form-group has-feedback">
<asp:TextBox ID="txtUserName" runat="server" autocomplete="off" class="validate[required] form-control"
placeholder="User Name">
</asp:TextBox>
</div>
<asp:Button ID="btnlogin" Text="تسجیل دخول" runat="server" Class="btn btn-primary btn-block btn-flat"
OnClick="btnlogin_Click" />
</div>
</div>
</asp:Content>
protected void btnlogin_Click(object sender, EventArgs e)
{
string watermarkText = txtUserName.Text;
System.Drawing.Image defaultImage = System.Drawing.Image.FromFile(Server.MapPath("~/Images/imge.png"));
using (Bitmap bmp = new Bitmap(Server.MapPath("~/Images/imge.png"), false))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
//Set the Color of the Watermark text.
Brush brush = new SolidBrush(Color.Red);
//Set the Font and its size.
Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);
//Determine the size of the Watermark text.
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
//Position the text and draw it on the image.
Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
grp.DrawString(watermarkText, font, brush, position);
using (MemoryStream memoryStream = new MemoryStream())
{
//Save the Watermarked image to the MemoryStream.
bmp.Save(memoryStream, ImageFormat.Png);
memoryStream.Position = 0;
//Start file download.
Response.Clear();
Response.ContentType = "image/png";
Response.AddHeader("Content-Disposition", "attachment; filename=" + defaultImage);
//Write the MemoryStream to the Response.
memoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.Close();
Response.End();
}
}
}
}
How to get solution pls.