case:Str.Length
Str.Font……
Str.Font……
解决方案 »
- 如何屏蔽和恢复windows的鼠标双击事件
- 求助个C#的算法
- 【算法比赛】在一亿个数中寻找出现频率最多的4个。
- 关于wcf中ServiceBehavior的设置
- 大家说说我要多久才能拿到我下一个三角
- 为什么页面刷新会调用DataGrid1_EditCommand事件
- 我想在“Application.Run(new MainForm())”之前实例化一个结构体并在几个不同的类中做实参调用,请问我该怎么写代码,在线等……
- 开始学C#.net 装上了六张盘后,开始学习,可是.........
- 问个简单的问题就是一个窗体要怎么样才可以最小化到屏幕的右下角?(就象MSN的最小化一样)
- 问个很愚蠢的问题
- 为什么在 Access 里这个 SQL 子查询查不到结果呢?
- c#中有类似画矩形、椭圆等形状的控件嘛?
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;namespace WebApplication1
{
/// <summary>
/// ToImage 的摘要说明。
/// </summary>
public class ToImage
{
public ToImage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//此函数的原型是实现网页计数器
public void stringToImage(string Content,string Style)
{
/*
Content 表示要显示的内容
style 表示计数器样式
*/
string strFontName; //字体名
int intFontSize; //字体大小
int intWidth; //图像宽
int intHeight; //图像长
//根据样式确定字体和大小
switch(Style)
{
case "1":
strFontName = "仿宋_GB2312";
intFontSize = 8;
intWidth = 40;
intHeight = 20;
break;
case "2":
strFontName = "宋体";
intFontSize = 10;
intWidth = 50;
intHeight = 20;
break;
case "3":
strFontName = "黑体";
intFontSize = 12;
intWidth = 60;
intHeight = 25;
break;
case "4":
strFontName = "楷体_GB2312";
intFontSize = 100;
intWidth = 280;
intHeight = 30;
break;
default:
strFontName = "新宋体";
intFontSize = 10;
intWidth = 50;
intHeight = 20;
break;
}
//背景颜色
Color bgColor = Color.Yellow;
//前景颜色
Color foreColor = Color.Red; //字体产生
Font foreFont = new Font(strFontName,intFontSize,FontStyle.Bold); /*
从这里开始产生
首先产生一个画布
*/
Bitmap newBitmap = new Bitmap(intWidth,intHeight,PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(newBitmap);
Rectangle newRect = new Rectangle(0,0,intWidth,intHeight);
//涂上背景色
g.FillRectangle(new SolidBrush(bgColor),newRect);
//写字
g.DrawString(Content.ToString(),foreFont,new SolidBrush(foreColor),2,2);
MemoryStream mStream = new MemoryStream();
//存入MemoryStream
newBitmap.Save(mStream,ImageFormat.Gif);
g.Dispose();
newBitmap.Dispose();
//发送
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ContentType = "image/GIF";
System.Web.HttpContext.Current.Response.BinaryWrite(mStream.ToArray());
System.Web.HttpContext.Current.Response.End();
}
//
public void textToImage(string text)
{
Color bgcolor=Color.Blue;
Color forecolor=Color.Red;
Font forefont=new Font("楷体_GB2312",23,FontStyle.Bold);
Bitmap newbitmap=new Bitmap(200,400,PixelFormat.Format32bppArgb);
Graphics g=Graphics.FromImage(newbitmap);
Rectangle newrect=new Rectangle(0,0,200,400);
g.FillRectangle(new SolidBrush(bgcolor),newrect);
//绘制字符串图片
g.DrawString(text.ToString(),forefont,new SolidBrush(forecolor),2,2);
//画弧
Pen newpen=new Pen(new SolidBrush(forecolor),5);
g.DrawArc(newpen,newrect,180,270);
//绘制贝赛尔样条
g.DrawBezier(newpen,new Point(12,45),new Point(56,89),new Point(123,200),new Point(56,67));
//绘制ico
Icon newicon=new Icon(System.Web.HttpContext.Current.Server.MapPath("img/project.ico"));
g.DrawIcon(newicon,new Rectangle(0,0,80,80));
//绘制image
// Image newimage=Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("imgs/097.GIF"));
Image newimage=Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("img/project.ico"));
g.DrawImage(newimage,new Rectangle(50,50,150,150),0,0,100,100,GraphicsUnit.Pixel);
g.DrawImageUnscaled(newimage,100,100,200,200);
//绘制一系列由直线、曲线等组成的图像路径
GraphicsPath graphPath=new GraphicsPath();
graphPath.AddEllipse(100,100,50,50);
graphPath.AddLine(12,89,120,200);
g.DrawPath(new Pen(new SolidBrush(Color.Black),3),graphPath);
// //回放增强型图元文件
// Metafile metafile=new Metafile(System.Web.HttpContext.Current.Server.MapPath("imgs/TN.emf"));
// g.DrawImage(metafile,50,50);
//将图片存入内存流
MemoryStream ms=new MemoryStream();
newbitmap.Save(ms,ImageFormat.Gif);
//释放资源
g.Dispose();
newbitmap.Dispose();
//显示图片
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ContentType = "image/GIF";
System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray());
System.Web.HttpContext.Current.Response.End();
}
}
}
还是非常感谢两位。