首先请大家测试上面的这个图片。主意TEKSTI关键字的值。
它应该是读出一个图片文件,然后写了一个字符串上去。
偶的问题是:在ASPX中如何实现这样的效果?对中文如何支持?以为上面的地址不能支持中文显示。
请大家讨论。
谢谢了,先。
6 个解决方案
#1
encode()
#2
有用的就三地方:读取图片、写入自己的文字、显示。
//////////////////////////////////////////////////////
///自动生成部门的业务处理情况图
int mAgree = Int32.Parse(Request.QueryString["Agree"]);
int mDisAgree = Int32.Parse(Request.QueryString["DisAgree"]);
int mTotal = mAgree + mDisAgree;
System.Drawing.Image fileImg =
System.Drawing.Bitmap.FromFile
(Server.MapPath("Images/pie_bg_2.gif"));
Bitmap mBitmap = new Bitmap(420,100,PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(mBitmap);
g.DrawImageUnscaled(fileImg,0,0,fileImg.Width,
fileImg.Height);
//g.DrawString("××部门业务处理情况分布图",new Font("宋体",16),Brushes.Black,new Point(5,5));
if (mTotal>0)
{
float mCurrentAngle = 0;
float mStartAngle = 0;
int mXLength = 170;
int mYLength = 66;
string mPercentA = (mAgree*100/mTotal).ToString() + "%";
string mPercentB = (mDisAgree*100/mTotal).ToString() + "%";
mCurrentAngle = (mAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Green ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle;
g.DrawString(mPercentA,new Font("宋体",10),Brushes.Black,new Point(320,16));
g.DrawString("共 " + mAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,16));
mCurrentAngle = (mDisAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Red ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle ;
g.DrawString(mPercentB,new Font("宋体",10),Brushes.Black,new Point(320,34));
g.DrawString("共 " + mDisAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,34));
}
mBitmap.Save(Response.OutputStream,ImageFormat.Jpeg);
fileImg.Dispose();
mBitmap.Dispose();
g.Dispose();
//////////////////////////////////////////////////////
///自动生成部门的业务处理情况图
int mAgree = Int32.Parse(Request.QueryString["Agree"]);
int mDisAgree = Int32.Parse(Request.QueryString["DisAgree"]);
int mTotal = mAgree + mDisAgree;
System.Drawing.Image fileImg =
System.Drawing.Bitmap.FromFile
(Server.MapPath("Images/pie_bg_2.gif"));
Bitmap mBitmap = new Bitmap(420,100,PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(mBitmap);
g.DrawImageUnscaled(fileImg,0,0,fileImg.Width,
fileImg.Height);
//g.DrawString("××部门业务处理情况分布图",new Font("宋体",16),Brushes.Black,new Point(5,5));
if (mTotal>0)
{
float mCurrentAngle = 0;
float mStartAngle = 0;
int mXLength = 170;
int mYLength = 66;
string mPercentA = (mAgree*100/mTotal).ToString() + "%";
string mPercentB = (mDisAgree*100/mTotal).ToString() + "%";
mCurrentAngle = (mAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Green ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle;
g.DrawString(mPercentA,new Font("宋体",10),Brushes.Black,new Point(320,16));
g.DrawString("共 " + mAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,16));
mCurrentAngle = (mDisAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Red ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle ;
g.DrawString(mPercentB,new Font("宋体",10),Brushes.Black,new Point(320,34));
g.DrawString("共 " + mDisAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,34));
}
mBitmap.Save(Response.OutputStream,ImageFormat.Jpeg);
fileImg.Dispose();
mBitmap.Dispose();
g.Dispose();
#3
咳,用层不就行了吗?图片在下面,上面加个层(iframe),层里面放置你的文字。
#4
1、 simon8181()的意思是?偶还不怎么明白,请明示。
2、 itbaba(itbaba) 的代码给人帮助很大。谢谢。
3、 sweet12345(努力就会有希望) ,层?不好了。那样不能实现图片的输入。我要的是输出合成了文字的图片。
2、 itbaba(itbaba) 的代码给人帮助很大。谢谢。
3、 sweet12345(努力就会有希望) ,层?不好了。那样不能实现图片的输入。我要的是输出合成了文字的图片。
#5
简单 我的程序就是这样做的
1 首先配置iis将jpg的解释交给.net
2 定义接口 在jpg图片里面添加文字 在显示 代码如下
using System.Web;
using System;
using System.IO;
using System.Drawing;
namespace cqcnc
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Expires = 0;//设置客户端缓冲中文件过期时间为0,即立即过期。
ctx.Response.Clear();//清空服务器端为此会话开辟的输出缓存
try
{
if(ctx.Request.UrlReferrer.Host=="bbs.cqwin.com"||ctx.Request.UrlReferrer.Host=="www.cqlife.com")
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
else
{
try
{
System.Drawing.Image image = Image.FromFile(ctx.Request.PhysicalPath);
int w = image.Width;
int h = image.Height;
//图片太小不用处理了。
if (image.Width < 300 || image.Height < 200)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
return;
}
Graphics g = Graphics.FromImage(image);
//写版权文字
g.DrawString("图片来源:Http://bbs.cqwin.com ", new Font("宋体",3), Brushes.White, new PointF(w - 200, h - 40));
g.Save();
Bitmap bmp = new Bitmap(image);
ctx.Response.ContentType="image/JPEG";
bmp.Save(ctx.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bmp.Dispose();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
catch(Exception ex)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
//ctx.Response.ContentType = MyFileCollection[0].ContentType;//getContentType(ctx.Request.PhysicalPath); //获得文件类型
//ctx.Response.WriteFile(ctx.Request.PhysicalPath);//将请求文件写入到服务器端为此会话开辟的输出缓存中
ctx.Response.End();//将服务器端为此会话开辟的输出缓存中的信息传送到客户端*/
}
public bool IsReusable
{
get { return true; }
}
System.Drawing.Imaging.ImageFormat GetImageFormat(string FileName)
{
string ext = System.IO.Path.GetExtension(FileName);
System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
switch(ext.ToLower())
{
case "jpg":
fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "jpeg":
goto case "jpg";
case "gif":
fmt = System.Drawing.Imaging.ImageFormat.Gif;
break;
case "bmp":
fmt = System.Drawing.Imaging.ImageFormat.Bmp;
break;
case "png":
fmt = System.Drawing.Imaging.ImageFormat.Png;
break;
}
return fmt;
}
}
}
1 首先配置iis将jpg的解释交给.net
2 定义接口 在jpg图片里面添加文字 在显示 代码如下
using System.Web;
using System;
using System.IO;
using System.Drawing;
namespace cqcnc
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Expires = 0;//设置客户端缓冲中文件过期时间为0,即立即过期。
ctx.Response.Clear();//清空服务器端为此会话开辟的输出缓存
try
{
if(ctx.Request.UrlReferrer.Host=="bbs.cqwin.com"||ctx.Request.UrlReferrer.Host=="www.cqlife.com")
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
else
{
try
{
System.Drawing.Image image = Image.FromFile(ctx.Request.PhysicalPath);
int w = image.Width;
int h = image.Height;
//图片太小不用处理了。
if (image.Width < 300 || image.Height < 200)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
return;
}
Graphics g = Graphics.FromImage(image);
//写版权文字
g.DrawString("图片来源:Http://bbs.cqwin.com ", new Font("宋体",3), Brushes.White, new PointF(w - 200, h - 40));
g.Save();
Bitmap bmp = new Bitmap(image);
ctx.Response.ContentType="image/JPEG";
bmp.Save(ctx.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bmp.Dispose();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
catch(Exception ex)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
//ctx.Response.ContentType = MyFileCollection[0].ContentType;//getContentType(ctx.Request.PhysicalPath); //获得文件类型
//ctx.Response.WriteFile(ctx.Request.PhysicalPath);//将请求文件写入到服务器端为此会话开辟的输出缓存中
ctx.Response.End();//将服务器端为此会话开辟的输出缓存中的信息传送到客户端*/
}
public bool IsReusable
{
get { return true; }
}
System.Drawing.Imaging.ImageFormat GetImageFormat(string FileName)
{
string ext = System.IO.Path.GetExtension(FileName);
System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
switch(ext.ToLower())
{
case "jpg":
fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "jpeg":
goto case "jpg";
case "gif":
fmt = System.Drawing.Imaging.ImageFormat.Gif;
break;
case "bmp":
fmt = System.Drawing.Imaging.ImageFormat.Bmp;
break;
case "png":
fmt = System.Drawing.Imaging.ImageFormat.Png;
break;
}
return fmt;
}
}
}
#6
在web.config里面这样配置
<add verb="*" path="*.jpg" type="cqcnc.MyHandler,cqcnc" />
</httpHandlers>
<httpRuntime
appRequestQueueLimit="200"
/>
<add verb="*" path="*.jpg" type="cqcnc.MyHandler,cqcnc" />
</httpHandlers>
<httpRuntime
appRequestQueueLimit="200"
/>
#1
encode()
#2
有用的就三地方:读取图片、写入自己的文字、显示。
//////////////////////////////////////////////////////
///自动生成部门的业务处理情况图
int mAgree = Int32.Parse(Request.QueryString["Agree"]);
int mDisAgree = Int32.Parse(Request.QueryString["DisAgree"]);
int mTotal = mAgree + mDisAgree;
System.Drawing.Image fileImg =
System.Drawing.Bitmap.FromFile
(Server.MapPath("Images/pie_bg_2.gif"));
Bitmap mBitmap = new Bitmap(420,100,PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(mBitmap);
g.DrawImageUnscaled(fileImg,0,0,fileImg.Width,
fileImg.Height);
//g.DrawString("××部门业务处理情况分布图",new Font("宋体",16),Brushes.Black,new Point(5,5));
if (mTotal>0)
{
float mCurrentAngle = 0;
float mStartAngle = 0;
int mXLength = 170;
int mYLength = 66;
string mPercentA = (mAgree*100/mTotal).ToString() + "%";
string mPercentB = (mDisAgree*100/mTotal).ToString() + "%";
mCurrentAngle = (mAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Green ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle;
g.DrawString(mPercentA,new Font("宋体",10),Brushes.Black,new Point(320,16));
g.DrawString("共 " + mAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,16));
mCurrentAngle = (mDisAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Red ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle ;
g.DrawString(mPercentB,new Font("宋体",10),Brushes.Black,new Point(320,34));
g.DrawString("共 " + mDisAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,34));
}
mBitmap.Save(Response.OutputStream,ImageFormat.Jpeg);
fileImg.Dispose();
mBitmap.Dispose();
g.Dispose();
//////////////////////////////////////////////////////
///自动生成部门的业务处理情况图
int mAgree = Int32.Parse(Request.QueryString["Agree"]);
int mDisAgree = Int32.Parse(Request.QueryString["DisAgree"]);
int mTotal = mAgree + mDisAgree;
System.Drawing.Image fileImg =
System.Drawing.Bitmap.FromFile
(Server.MapPath("Images/pie_bg_2.gif"));
Bitmap mBitmap = new Bitmap(420,100,PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(mBitmap);
g.DrawImageUnscaled(fileImg,0,0,fileImg.Width,
fileImg.Height);
//g.DrawString("××部门业务处理情况分布图",new Font("宋体",16),Brushes.Black,new Point(5,5));
if (mTotal>0)
{
float mCurrentAngle = 0;
float mStartAngle = 0;
int mXLength = 170;
int mYLength = 66;
string mPercentA = (mAgree*100/mTotal).ToString() + "%";
string mPercentB = (mDisAgree*100/mTotal).ToString() + "%";
mCurrentAngle = (mAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Green ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle;
g.DrawString(mPercentA,new Font("宋体",10),Brushes.Black,new Point(320,16));
g.DrawString("共 " + mAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,16));
mCurrentAngle = (mDisAgree*360)/mTotal;
g.FillPie ( new SolidBrush ( Color.Red ) , 11 , 11 , mXLength , mYLength , mStartAngle , mCurrentAngle ) ;
mStartAngle += mCurrentAngle ;
g.DrawString(mPercentB,new Font("宋体",10),Brushes.Black,new Point(320,34));
g.DrawString("共 " + mDisAgree.ToString() + " 笔",new Font("宋体",10),Brushes.Black,new Point(350,34));
}
mBitmap.Save(Response.OutputStream,ImageFormat.Jpeg);
fileImg.Dispose();
mBitmap.Dispose();
g.Dispose();
#3
咳,用层不就行了吗?图片在下面,上面加个层(iframe),层里面放置你的文字。
#4
1、 simon8181()的意思是?偶还不怎么明白,请明示。
2、 itbaba(itbaba) 的代码给人帮助很大。谢谢。
3、 sweet12345(努力就会有希望) ,层?不好了。那样不能实现图片的输入。我要的是输出合成了文字的图片。
2、 itbaba(itbaba) 的代码给人帮助很大。谢谢。
3、 sweet12345(努力就会有希望) ,层?不好了。那样不能实现图片的输入。我要的是输出合成了文字的图片。
#5
简单 我的程序就是这样做的
1 首先配置iis将jpg的解释交给.net
2 定义接口 在jpg图片里面添加文字 在显示 代码如下
using System.Web;
using System;
using System.IO;
using System.Drawing;
namespace cqcnc
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Expires = 0;//设置客户端缓冲中文件过期时间为0,即立即过期。
ctx.Response.Clear();//清空服务器端为此会话开辟的输出缓存
try
{
if(ctx.Request.UrlReferrer.Host=="bbs.cqwin.com"||ctx.Request.UrlReferrer.Host=="www.cqlife.com")
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
else
{
try
{
System.Drawing.Image image = Image.FromFile(ctx.Request.PhysicalPath);
int w = image.Width;
int h = image.Height;
//图片太小不用处理了。
if (image.Width < 300 || image.Height < 200)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
return;
}
Graphics g = Graphics.FromImage(image);
//写版权文字
g.DrawString("图片来源:Http://bbs.cqwin.com ", new Font("宋体",3), Brushes.White, new PointF(w - 200, h - 40));
g.Save();
Bitmap bmp = new Bitmap(image);
ctx.Response.ContentType="image/JPEG";
bmp.Save(ctx.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bmp.Dispose();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
catch(Exception ex)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
//ctx.Response.ContentType = MyFileCollection[0].ContentType;//getContentType(ctx.Request.PhysicalPath); //获得文件类型
//ctx.Response.WriteFile(ctx.Request.PhysicalPath);//将请求文件写入到服务器端为此会话开辟的输出缓存中
ctx.Response.End();//将服务器端为此会话开辟的输出缓存中的信息传送到客户端*/
}
public bool IsReusable
{
get { return true; }
}
System.Drawing.Imaging.ImageFormat GetImageFormat(string FileName)
{
string ext = System.IO.Path.GetExtension(FileName);
System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
switch(ext.ToLower())
{
case "jpg":
fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "jpeg":
goto case "jpg";
case "gif":
fmt = System.Drawing.Imaging.ImageFormat.Gif;
break;
case "bmp":
fmt = System.Drawing.Imaging.ImageFormat.Bmp;
break;
case "png":
fmt = System.Drawing.Imaging.ImageFormat.Png;
break;
}
return fmt;
}
}
}
1 首先配置iis将jpg的解释交给.net
2 定义接口 在jpg图片里面添加文字 在显示 代码如下
using System.Web;
using System;
using System.IO;
using System.Drawing;
namespace cqcnc
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Expires = 0;//设置客户端缓冲中文件过期时间为0,即立即过期。
ctx.Response.Clear();//清空服务器端为此会话开辟的输出缓存
try
{
if(ctx.Request.UrlReferrer.Host=="bbs.cqwin.com"||ctx.Request.UrlReferrer.Host=="www.cqlife.com")
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
else
{
try
{
System.Drawing.Image image = Image.FromFile(ctx.Request.PhysicalPath);
int w = image.Width;
int h = image.Height;
//图片太小不用处理了。
if (image.Width < 300 || image.Height < 200)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
return;
}
Graphics g = Graphics.FromImage(image);
//写版权文字
g.DrawString("图片来源:Http://bbs.cqwin.com ", new Font("宋体",3), Brushes.White, new PointF(w - 200, h - 40));
g.Save();
Bitmap bmp = new Bitmap(image);
ctx.Response.ContentType="image/JPEG";
bmp.Save(ctx.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bmp.Dispose();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
catch(Exception ex)
{
ctx.Response.WriteFile(ctx.Request.PhysicalPath);
}
//ctx.Response.ContentType = MyFileCollection[0].ContentType;//getContentType(ctx.Request.PhysicalPath); //获得文件类型
//ctx.Response.WriteFile(ctx.Request.PhysicalPath);//将请求文件写入到服务器端为此会话开辟的输出缓存中
ctx.Response.End();//将服务器端为此会话开辟的输出缓存中的信息传送到客户端*/
}
public bool IsReusable
{
get { return true; }
}
System.Drawing.Imaging.ImageFormat GetImageFormat(string FileName)
{
string ext = System.IO.Path.GetExtension(FileName);
System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
switch(ext.ToLower())
{
case "jpg":
fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "jpeg":
goto case "jpg";
case "gif":
fmt = System.Drawing.Imaging.ImageFormat.Gif;
break;
case "bmp":
fmt = System.Drawing.Imaging.ImageFormat.Bmp;
break;
case "png":
fmt = System.Drawing.Imaging.ImageFormat.Png;
break;
}
return fmt;
}
}
}
#6
在web.config里面这样配置
<add verb="*" path="*.jpg" type="cqcnc.MyHandler,cqcnc" />
</httpHandlers>
<httpRuntime
appRequestQueueLimit="200"
/>
<add verb="*" path="*.jpg" type="cqcnc.MyHandler,cqcnc" />
</httpHandlers>
<httpRuntime
appRequestQueueLimit="200"
/>