Hello Forum,
how do I create watermark text on image to save
when saving it will save the image with the watermark label text on it?
C#
protected void Button1_Click(object sender, EventArgs e)
{
// Read the file and convert it to Byte Array
string email = string.Empty;
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = string.Empty;
int size = FileUpload1.FileBytes.Length;
//Set the contenttype
if (ext == ".jpg" || ext == ".png")
{
contenttype = "image/jpg";
}
if (contenttype != string.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string sql = "INSERT INTO CardTbl(email, Name, Contyp, Size, image, Uid, CreatedBy, Role, CreatedDate, Organization)" +
" VALUES(@email, @Name, @ContentType, @Size, @image, @Uid, @CreatedBy, @Role, @CreatedDate, @Organization); SELECT @@IDENTITY";
SqlParameter[] parameters = new[]
{
new SqlParameter("@email", user.Text.Trim()),
new SqlParameter("@Name",filename ),
new SqlParameter("@ContentType",contenttype ),
new SqlParameter("@Size",size ),
new SqlParameter("@image",bytes ),
new SqlParameter("@Uid", labelid.Text.Trim()),
new SqlParameter("@CreatedBy", createby.Text.Trim()),
new SqlParameter("@Role", role.Text.Trim()),
new SqlParameter("@CreatedDate", DateTime.Now),
new SqlParameter("@Organization", named.Text.Trim())
};
int id = ExecuteScalar(sql, parameters);
Session["CardId"] = id;
// Session["user"] = id;
if (id != -1)
{
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Text = "File Uploaded Successfully";
// Return a QR pic
BindCardAndQR();
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "File Uploaded Failed";
}
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "File format not recognised." + "JPG/PNG Formats ONLY";
}
}
public byte[] GetQRCodeBytes(string url)
{
QRCodeEncoder encoder = new QRCodeEncoder();
Bitmap bi = encoder.Encode(url);
MemoryStream tmpSteam = new MemoryStream();
bi.Save(tmpSteam, ImageFormat.Jpeg);
return tmpSteam.ToArray();
}