imageComponent.NET title a curve
   Home Page | Blog | Online Forum | Links | SiteMap
Skip Navigation Links.
- Recommended .NET Book -

MCAD/MCSD Self-Paced Training Kit: Microsoft .NET Core Requirements, Exams

Book Description Four kits in one! Get self-paced preparation for the skills measured by the...[more]
Skip Navigation LinksHome > Products > CoolWatermark > Demo for v2.x

Overview

This page demonstrates a simple program working CoolWatermark and PhotoController v2.0 together. In the following form, select a shape in the new version 2.0 of CoolWatermark, then click [Apply] button, the program will draw the watermark text with a Marble effect generated by PhotoController v2.0. The source code is at the end of this page.

Enter the text you want to write to the following image:


Select the shape of the watermark text:
  

Original Test Image


Source Code

The following source shows the code behind of the above sample. It has several steps:
  • Write the watermark text to a blank and transparent canvas
  • Cut only the text portion from the canvas
  • Apply MarbleFilter to text
  • Write the overlapped text image to our destination image
Note: MarbleFilter is a sort of dither, so the sample really doesn't significantly show the Dither shape.

string shape = Request.QueryString["shape"].ToString();

 

// create a large enough canvas, and it must be 32bppArgb, which supports transparency

Bitmap canvas = new Bitmap(640, 480, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

Graphics g = Graphics.FromImage(canvas);

 

// make the canvas transparent

g.Clear(Color.Transparent);

g.Dispose();

 

IC.CoolWatermark.Writer cw = new Writer(canvas);

IC.CoolWatermark.Shape textShape;

 

// setup the textShape

switch (shape)

{

    case "Dither":

        {

            textShape = new Shape( ShapeStyle.Dither );

            break;

        }

    case "RainbowUpper":

        {

            textShape = new Shape(ShapeStyle.RainbowUpper);

            break;

        }

    case "RainbowLower":

        {

            textShape = new Shape(ShapeStyle.RainbowLower);

            break;

        }

    default: // otherwise just use Bulge if the querystring

        {

            textShape = new Shape(ShapeStyle.Bulge);

            break;

        }

} // end switch

 

cw.Shape = textShape;

cw.PositionStyle = PositionStyle.MiddleCenter;

cw.FontSize = 48;

cw.FontStyle = FontStyle.Bold;

cw.FontFamily = new FontFamily("Impact");

cw.Spacing = 0;

cw.Colors = new Color[] { Color.Red };

cw.WriteText(text);

 

// create a new bitmap to store the text bitmap

Bitmap textBitmap = new Bitmap(cw.BoundedSize.Width, cw.BoundedSize.Height, PixelFormat.Format32bppArgb);

g = Graphics.FromImage(textBitmap);

g.Clear(Color.Transparent);

// cut the text portion to the textBitmap

g.DrawImage(cw.Image, 0, 0, cw.BoundedArea, GraphicsUnit.Pixel);

g.Dispose();

 

// we don't need canvas now

canvas.Dispose();

 

// release this first, and we will need a new one

cw.Dispose();

 

// let's marble the textBitmap first

IC.PhotoController.Controller pc = new IC.PhotoController.Controller(textBitmap);

// setup the marble filter

MarbleFilter filter = new MarbleFilter();

filter.Turbulence = 1;

filter.Movement = 3;

filter.Level = 10;

 

Bitmap final = new Bitmap(pc.Filter(filter));

pc.Dispose();

 

// this is the final step, we output the embossed text to the sample image

cw = new Writer(sample);

cw.PositionStyle = PositionStyle.MiddleCenter;

Bitmap result = new Bitmap( cw.WriteImage(final) );

 

// output to page

MemoryStream oStream = new MemoryStream();

result.Save(oStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Response.BinaryWrite(oStream.ToArray());

 

// release resources

cw.Dispose();

result.Dispose();

final.Dispose();

 



  Quick Search
Components
Books



Sponsors

  Home | Links | Blog | SiteMap | About | 2005-2007 © imageComponent.NET, All Rights Reserved.