C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Graphics »

Watermark on image : Draw string on the image


Posted Date: 05 Feb 2009    Resource Type: Code Snippets    Category: Graphics
Author: vipulMember Level: Diamond    
Rating: 1 out of 5Points: 10



Here i describe how to draw sting on any image. in that i used graphics class for that you can call this function in the page load or any button event and you have to just pass the string which you want to draw on the image.
this way


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddWatermark("Demo version");
}
}

public void AddWatermark(string watermarkText)
{
System.Drawing.Image bitmap = (System.Drawing.Image)Bitmap.FromFile(Server.MapPath("image\\img_tripod.jpg"));

Font font = new Font("Arial", 20, FontStyle.Italic, GraphicsUnit.Pixel);

Color color = Color.FromArgb(255, 255, 0, 0);
Point atpoint = new Point(bitmap.Width / 2, bitmap.Height / 2);
SolidBrush brush = new SolidBrush(color);
Graphics graphics = Graphics.FromImage(bitmap);

StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;


graphics.DrawString(watermarkText, font, brush, atpoint,sf);
graphics.Dispose();
MemoryStream m = new MemoryStream();
bitmap.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg);
m.WriteTo(Response.OutputStream);
m.Dispose();
base.Dispose();
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Water mark  .  Draw string on the image  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Silverlight : Creating Brush from Color name
Previous Resource: Create image from the text
Return to Discussion Resource Index
Post New Resource
Category: Graphics


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use