hi,
i am using image water mark code on listview data bound event and its give me error
The process cannot access the file 'E:\FIVERR\cinvest\CustomCoupon\ca00453f-c985-4794-9a87-36a60e2fa0e1.png' because it is being used by another process.
here is the code page behind code
System.Web.UI.WebControls.Image myimg;
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (!IsPostBack)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
myimg = ((System.Web.UI.WebControls.Image)e.Item.FindControl("Image1"));
string watermarkText = "© CINVEST";
string fileName = Server.MapPath(myimg.ImageUrl);
FileStream fs = new FileStream(fileName, FileMode.Open);
using (Bitmap bmp = new Bitmap(fs, false))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
Brush brush = new SolidBrush(Color.Red);
Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 80)));
grp.DrawString(watermarkText, font, brush, position);
using (MemoryStream memoryStream = new MemoryStream())
{
bmp.Save(memoryStream, ImageFormat.Png);
string base64String = Convert.ToBase64String(memoryStream.ToArray());
string imageUrl = "data:image/png;base64," + base64String;
myimg.Attributes.Add("src", imageUrl);
}
}
}
}
}
}