自动产生图片
2006-10-10 17:04
127 查看
一个动态生成各种格式图片的小程序,下面给出了生成jpg图片的代码,要生成其它格式,只需更改图片格式即可,代码如下:
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Bitmap newBitmap = null;
Graphics g = null;
try
{
Font fontCounter = new Font("华文彩云", 16);
// calculate size of the string.
newBitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
SizeF stringSize = g.MeasureString(TextBox1.Text , fontCounter);
int nWidth = (int)stringSize.Width;
int nHeight = (int)stringSize.Height;
g.Dispose();
newBitmap.Dispose();
newBitmap = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.Blue ),
new Rectangle(0, 0, nWidth, nHeight));
g.DrawString(TextBox1.Text, fontCounter,
new SolidBrush(Color.Yellow ), 0, 0);
newBitmap.Save(TextBox2.Text, ImageFormat.Jpeg);
}
finally
{
if (null != g) g.Dispose();
if (null != newBitmap) newBitmap.Dispose();
}
}
}
操作界面如下:
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Bitmap newBitmap = null;
Graphics g = null;
try
{
Font fontCounter = new Font("华文彩云", 16);
// calculate size of the string.
newBitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
SizeF stringSize = g.MeasureString(TextBox1.Text , fontCounter);
int nWidth = (int)stringSize.Width;
int nHeight = (int)stringSize.Height;
g.Dispose();
newBitmap.Dispose();
newBitmap = new Bitmap(nWidth, nHeight, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.Blue ),
new Rectangle(0, 0, nWidth, nHeight));
g.DrawString(TextBox1.Text, fontCounter,
new SolidBrush(Color.Yellow ), 0, 0);
newBitmap.Save(TextBox2.Text, ImageFormat.Jpeg);
}
finally
{
if (null != g) g.Dispose();
if (null != newBitmap) newBitmap.Dispose();
}
}
}
操作界面如下:
相关文章推荐
- NeuralTalk2---自动产生图片的语句描述
- ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题
- ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题
- NeuralTalk2---自动产生图片的语句描述
- 根据CDImage.cue产生自动改名命令的Python小程序
- Java 自动生成缩略图片
- 偶的小收获(关于验证码随机产生图片)
- Auto Layout 使用心得(五)—— 根据文字、图片自动计算 UITableViewCell 高度
- C# 图片框应用——图片自动浏览器
- ViewPager加载网络图片+自动轮播+小圆点指示
- HTML页面图片自动适应宽度
- js图片自动轮播代码分享(js图片轮播)
- 图片拖出相框,自动消失
- word2013 图片与表格自动更新编号
- JS 图片大小自动调整 (img)
- mvc4 截取上传图片做头像,自动生成不同小尺寸缩略图
- js鼠标点击按钮切换图片-图片自动切换-点击左右按钮切换特效代码
- ASP自动解析网页中的图片地址,并将其保存到本地服务器http://epasser.aydc.com.cn/article/adp/2/content13959.html
- 上传自动显示图片 代码
- 鼠标移动,图片自动切换(简化版)