hi
I used below code to upload image and put watermark on it
protected void BtnUpload_Click(object sender, EventArgs e)
{
uploadImageError.Visible = true;
if (fup1.HasFile && fup1.PostedFile.ContentLength < 102400)
{
string watermarkText = "behtop.com";
string path = Server.MapPath("~/image/House/product/");
string fileName = System.IO.Path.GetFileName(fup1.PostedFile.FileName);
if (Array.IndexOf(new string[] { ".jpg", ".png" }, System.IO.Path.GetExtension(fup1.PostedFile.FileName).ToString().ToLower()) < 0)
{
uploadImageError.Text = "*لطفاً عکس با فرمت Png.* و Jpg.* آپلود نمایید.";
return;
}
while (System.IO.File.Exists(path + "\\" + fileName))
{
fileName = "1" + fileName;
}
using (Bitmap bmp = new Bitmap(fup1.PostedFile.InputStream, false))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
//Set the Color of the Watermark text.
Brush brush = new SolidBrush(Color.FromArgb(50, 255, 255, 255));
//Set the Font and its size.
Font font = new System.Drawing.Font("tahoma", 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 + 100)), (bmp.Height - ((int)textSize.Height + 100)));
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=" + fileName);
//Write the MemoryStream to the Response.
memoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.Close();
Response.End();
fup1.PostedFile.SaveAs(path + fileName);
ViewState["Id"] = House_p.SaveImageName(fileName, Session["behcode"].ToString(), Convert.ToInt32(ViewState["Id"]));
uploadImageError.Text = "*عکس شما با موفقیت بارگذاری شد";
this.imgProduct.ImageUrl = GetThumbNail("~/image/house/product/" + fileName);
lblProduct.Visible = upUploadImage.Visible = !(btnDeleteImage.Visible = imgProduct.Visible = true);
lblErrorSubmit.Text = " ";
}
}
}
}
else
{
uploadImageError.Text = "*حجم فایل شما" + Convert.ToString(fup1.PostedFile.ContentLength / 1024) + "KB می باشد لطفاعکس با حجم کمتر از100 KB آپلود نمایید.";
}
}
problem is when I upload image and click on btnupload it shows image in new window with watermark text but it doesn't save it into host...
I want when I click on btnupload it doesn't show image in new window I want it just uploaded image with watermark into host...
How I can do it?
best regards
neda