Below is the method which will add a text as a water marked text to an image.
public Bitmap WaterMarkToImage(string ImagePath, string watermark)
{
Bitmap bmp;
bmp = new Bitmap(ImagePath);
Graphics graphicsObject;
int x, y;
try
{
//create graphics object from bitmap
graphicsObject = Graphics.FromImage(bmp);
}
catch (Exception e)
{
Bitmap bmpNew = new Bitmap(bmp.Width, bmp.Height);
graphicsObject = Graphics.FromImage(bmpNew);
graphicsObject.DrawImage(bmp, new Rectangle(0, 0,
bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width,
bmp.Height, GraphicsUnit.Pixel);
bmp = bmpNew;
}
int startsize = (bmp.Width / watermark.Length);
//get the font size with respect to length of the string
//x and y cordinates to draw a string
x = 0;
y = bmp.Height / 2;
System.Drawing.StringFormat drawFormat =
new System.Drawing.StringFormat(StringFormatFlags.NoWrap);
//drawing string on Image
graphicsObject.DrawString(watermark, new Font("Verdana",
startsize, FontStyle.Bold),
new SolidBrush(Color.FromArgb(100, 255, 255, 255)), x, y, drawFormat);
//return a water marked image
return (bmp);
}
Method Call:
System.Drawing.Bitmap bmp =
WaterMarkToImage(@"D:\images\IMG_2933.jpg", "Intraspatial Softech");
bmp.Save(@"D:\images\c1.jpg");
May 17, 2010
May 14, 2010
Problem calling Java-script method from codebehind with master-page and update panel
we normally use
Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "Sys.Application.add_load(method_Name);", true);
to call a javascript on runtime form code behind.
Placing the above code on page load or a button click makes the script to fire on the start up of subsequent postback.
But this make not work in the case where we give a
ajax post back intead of normal postback.
so to call a javascript method on ajax postback , here we go
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Key", "ServiceDownAlert();", true);
Javascript Method:
function ServiceDownAlert() {
alert("Image Not Available ! Please Try Later !");
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "Sys.Application.add_load(method_Name);", true);
to call a javascript on runtime form code behind.
Placing the above code on page load or a button click makes the script to fire on the start up of subsequent postback.
But this make not work in the case where we give a
ajax post back intead of normal postback.
so to call a javascript method on ajax postback , here we go
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Key", "ServiceDownAlert();", true);
Javascript Method:
function ServiceDownAlert() {
alert("Image Not Available ! Please Try Later !");
}
Subscribe to:
Posts (Atom)