Bitmap bitmap = new Bitmap(Server.MapPath("d:xxx.jpg"));
MemoryStream memStream = new MemoryStream();
// generate image
// Create a graphics object for drawing.
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
int width = bitmap.Width;
int height = bitmap.Height;
string familyName = "Tahoma";
string text = Request.Params["Text"];
// get a rectangle on his shirt
Rectangle rect = new Rectangle(150, 216, 210, 135);
// Set up the text font.
Font font;
font = new Font(familyName, 16F, FontStyle.Regular);
// Set up the text format.
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
// Create a path using the text and warp it to fit over his contour
GraphicsPath path = new GraphicsPath();
path.AddString(text, font.FontFamily, (int) font.Style, font.Size, rect, format);
PointF[] points =
{
new PointF(rect.X - 10, rect.Y - 8),
new PointF(rect.X + rect.Width - 20, rect.Y + 4),
new PointF(rect.X - 8, rect.Y + rect.Height - 15),
new PointF(rect.X + rect.Width - 10, rect.Y + rect.Height + 4)
};
Matrix matrix = new Matrix();
matrix.Translate(0F, 0F);
path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
// Draw the text.
HatchBrush hatchBrush = new HatchBrush(
HatchStyle.LargeConfetti,
Color.LightGray,
Color.DarkGray);
g.FillPath(hatchBrush, path);
Response.Clear();
Response.ContentType="image/jpeg";
bitmap.Save(memStream, ImageFormat.Jpeg);
memStream.WriteTo(Response.OutputStream);
// Clean up.
font.Dispose();
hatchBrush.Dispose();
g.Dispose();
bitmap.Dispose();