Home
Suggestion or Comment?
Check Bytescout.Watermarking SDK for .NET to add more attractive watermarks with ready-to-use customizable presets


Subscribe to Our Bi-Monthly Newsletter (tips, new releases, specials):
 Subscribe in a reader
 PRODUCTS  |  DOWNLOAD  |  PURCHASE  |  SUPPORT  |  TESTIMONIALS   |  NEWS  | 

Tutorial: how to add watermark to a picture using built-in .NET functionality


Looking for a component to add watermarks based on ready-to-use presets?
Check Bytescout.Watermarking SDK for .NET to add more attractive watermarks with ready-to-use customizable presets

This tutorial demonstrates how to add a red text (watermark) to the photo file using .NET built-in functionality without any 3rd party components and libraries (like our Watermarking SDK) in ASP.NET web-application

Download source code for this example: HowToAddWatermarkToImageInDotNetWithout3rdPartyTools_asp.zip (300 KB)

Input image:

sample input image

Output image:

output image (text fits page preset)

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Load image
System.Drawing.Image image = System.Drawing.Image.FromFile("my_sample_image.jpg");
// Create graphics from image
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image);
// Create font
System.Drawing.Font font = new System.Drawing.Font("Times New Roman", 42.0f);
// Create text position
System.Drawing.PointF point = new System.Drawing.PointF(150, 150);
// Draw text
graphics.DrawString("Watermark", font, System.Drawing.Brushes.Red, point);

// clear http output
Response.Clear();
// set the content type to JPEG
Response.ContentType = "image/jpeg";
// add content type header
Response.AddHeader("Content-Type", "image/jpeg");
// set the content disposition
Response.AddHeader("Content-Disposition", "inline;filename=my_sample_image.jpg");
// Save image
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Response.End();
}
}

Download source code for this example: HowToAddWatermarkToImageInDotNetWithout3rdPartyTools_asp.zip (300 KB)

 

Looking for a component to add watermarks based on ready-to-use presets?
Check Bytescout.Watermarking SDK for .NET to add more attractive watermarks with ready-to-use customizable presets

HOME  |  CONTACT US

Copyright © ByteScout, 2003-2010. Privacy Statement
Microsoft®, Windows®, Windows 2000®, Windows Server®, Windows Vista®, Internet Explorer®, .NET Framework®, ActiveX®, Visual Basic®, Visual C#®, ASP®, ASP.NET®, Excel®, PowerPoint®, are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Adobe®, Flash® and Acrobat® are registered trademarks of Adobe Systems, Incorporated. Mozilla®, Firefox® and the Mozilla and Firefox Logos are registered trademarks of the Mozilla Foundation. Other product names or brandnames used herein are for identification purposes only and might be trademarks or registered trademarks of their respective companies. We disclaim any and all rights to those marks.