Friday, February 17, 2012

Watermark Text within Image



Code Related to Static Image

.vb

Imports System.IO
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Drawing.Imaging


 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 Dim objImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("Chrysanthemum.jpg"))
        'Taken Actual width anf height From Image
        Dim height As Integer = objImage.Height
        'height
        Dim width As Integer = objImage.Width
        'Width
        'Create a Bitmap Image
        Dim bitmapimage As New System.Drawing.Bitmap(objImage, width, height)
        ' create bitmap with same size of Actual image
        'Convert in to a Graphics object
        Dim g As System.Drawing.Graphics = 
System.Drawing.Graphics.FromImage(bitmapimage)


' TO SET THE Watermark Text angle 
'--------------------------------------

g.FillRectangle(Brushes.White, 0, 0, 0, 0)
        g.TranslateTransform(100, 100)
        g.RotateTransform(-30)
'----------------------------------------
        'Creating Brush


        Dim brush As New System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(113, 255, 255, 255))
'set text position on image
        g.DrawString("Anish", New Font("Arial", 18, System.Drawing.FontStyle.Bold), brush, 0, 100)
        Response.ContentType = "image/jpeg"
        'setting ContentType


        bitmapimage.Save(Response.OutputStream, ImageFormat.Jpeg)
    End Sub
'-------------------------------------------------------------
.c#



using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Drawing.Imaging;


protected void Page_Load(object sender, System.EventArgs e)
{
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("Chrysanthemum.jpg"));


//Taken Actual width anf height From Image
int height = objImage.Height;
//height
int width = objImage.Width;
//Width
//Create a Bitmap Image
System.Drawing.Bitmap bitmapimage = new System.Drawing.Bitmap(objImage, width, height);
// create bitmap with same size of Actual image
//Convert in to a Graphics object
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapimage);


' TO SET THE Watermark Text angle 
'--------------------------------------

g.FillRectangle(Brushes.White, 0, 0, 0, 0);
        g.TranslateTransform(100, 100);
        g.RotateTransform(-30);
'----------------------------------------
//Creating Brush


System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(113, 255, 255, 255));
//set text position on image
g.DrawString(" Anish ", new Font("Arial", 18, System.Drawing.FontStyle.Bold), brush, 0, 100);
Response.ContentType = "image/jpeg";
//setting ContentType
bitmapimage.Save(Response.OutputStream, ImageFormat.Jpeg);
}


It will display watermark text on image



No comments:

Post a Comment