Mobile Content

Friday, February 17, 2012

Set The angle of Watermark Text in 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



Animation : Moving label text up/down continuously in asp.net


Animation using code


Here i am using updatepanel and timer to refresh page 

in .aspx


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="1000">
            </asp:Timer>


            <asp:Label ID="Lblanimation" runat="server" Text="Move Text"></asp:Label>


        </ContentTemplate>
  </asp:UpdatePanel>


in .cs page



if (ViewState["hit"] == null)
        {
            top = 1;
            top1 = 0;
           
        }
        else
        {
                     
           top = Convert.ToInt32(ViewState["hit"]);
           top1 = Convert.ToInt32(ViewState["hit1"]);
          
            if (top > 300 || top1>300)
            {
                top = (int)ViewState["hit"] - 1;
                top1 = (int)ViewState["hit1"] + 1;
                if (top == 1)
                {
                    top1 = 0;
                    left =Convert.ToInt32(ViewState["left"]) + 10;
                }
            }
            else
            {
                top = (int)ViewState["hit"] + 1;
                top1 = (int)ViewState["hit1"] + 1;
            }

        }
        lx.Attributes.Add("style", "top:"+top+"px;position:absolute;left:100px");
        ViewState["hit"] = top;
        ViewState["hit1"] = top1;
      

I have used viewstate to store the value generated when page get refresh

Label text move up and down continuously in every page refresh.
I have fixed the position up to 300 pixel. 




Watermark Text Behind 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)
        '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);
//Creating Brush
//set text position on image
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(113, 255, 255, 255));


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