ASP.NET中如何将输入的文体绘制在一张图片上
就是我想输入一段文字,点提交后,可以把这段文字绘制到一张图片上,让这张绘制好的图片的形势显示出来。有高手指点下,有源码更好,谢谢!...
就是我想输入一段文字,点提交后,可以把这段文字绘制到一张图片上,让这张绘制好的图片的形势显示出来。
有高手指点下,有源码更好,谢谢! 展开
有高手指点下,有源码更好,谢谢! 展开
2个回答
展开全部
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class ImageHelper
{
/// <summary><SUMMARY></SUMMARY>
/// 获取图片中的各帧
/// </summary>
/// <param name="pPath"><PARAM name="pPath" />图片路径</param>
/// <param name="pSavePath"><PARAM name="pSavePath" />保存路径</param>
public void GetFrames(string pPath, string pSavedPath)
{
Image gif = Image.FromFile(pPath);
FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
//获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
int count = gif.GetFrameCount(fd);
//以Jpeg格式保存各帧
for (int i = 0; i < count; i++)
{
gif.SelectActiveFrame(fd, i);
gif.Save(pSavedPath + "\\frame_" + i + ".jpg", ImageFormat.Jpeg);
}
}
/// <summary><SUMMARY></SUMMARY>
/// 获取图片缩略图
/// </summary>
/// <param name="pPath"><PARAM name="pPath" />图片路径</param>
/// <param name="pSavePath"><PARAM name="pSavePath" />保存路径</param>
/// <param name="pWidth"><PARAM name="pWidth" />缩略图宽度</param>
/// <param name="pHeight"><PARAM name="pHeight" />缩略图高度</param>
/// <param name="pFormat"><PARAM name="pFormat" />保存格式,通常可以是jpeg</param>
public void GetSmaller(string pPath, string pSavedPath, int pWidth, int pHeight)
{
try
{
Image smallerImg;
Image originalImg = Image.FromFile(pPath);
Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
smallerImg = originalImg.GetThumbnailImage(pWidth, pHeight, callback, IntPtr.Zero);
smallerImg.Save(pSavedPath + "\\smaller.jpg", ImageFormat.Jpeg);
}
catch (Exception x)
{
//
}
}
/// <summary><SUMMARY></SUMMARY>
/// 获取图片指定部分
/// </summary>
/// <param name="pPath"><PARAM name="pPath" />图片路径</param>
/// <param name="pSavePath"><PARAM name="pSavePath" />保存路径</param>
/// <param name="pPartStartPointX"><PARAM name="pPartStartPointX" />目标图片开始绘制处的坐标X值(通常为)</param>
/// <param name="pPartStartPointY"><PARAM name="pPartStartPointY" />目标图片开始绘制处的坐标Y值(通常为)</param>
/// <param name="pPartWidth"><PARAM name="pPartWidth" />目标图片的宽度</param>
/// <param name="pPartHeight"><PARAM name="pPartHeight" />目标图片的高度</param>
/// <param name="pOrigStartPointX"><PARAM name="pOrigStartPointX" />原始图片开始截取处的坐标X值</param>
/// <param name="pOrigStartPointY"><PARAM name="pOrigStartPointY" />原始图片开始截取处的坐标Y值</param>
/// <param name="pFormat"><PARAM name="pFormat" />保存格式,通常可以是jpeg</param>
public void GetPart(string pPath, string pSavedPath, int pPartStartPointX, int pPartStartPointY, int pPartWidth, int pPartHeight, int pOrigStartPointX, int pOrigStartPointY)
{
Image originalImg = Image.FromFile(pPath);
Bitmap partImg = new Bitmap(pPartWidth, pPartHeight);
Graphics graphics = Graphics.FromImage(partImg);
Rectangle destRect = new Rectangle(new Point(pPartStartPointX, pPartStartPointY), new Size(pPartWidth, pPartHeight));//目标位置
Rectangle origRect = new Rectangle(new Point(pOrigStartPointX, pOrigStartPointY), new Size(pPartWidth, pPartHeight));//原图位置(默认从原图中截取的图片大小等于目标图片的大小)
graphics.DrawImage(originalImg, destRect, origRect, GraphicsUnit.Pixel);
partImg.Save(pSavedPath + "\\part.jpg", ImageFormat.Jpeg);
}
public bool ThumbnailCallback()
{
return false;
}
}
希望对你有所帮助
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class ImageHelper
{
/// <summary><SUMMARY></SUMMARY>
/// 获取图片中的各帧
/// </summary>
/// <param name="pPath"><PARAM name="pPath" />图片路径</param>
/// <param name="pSavePath"><PARAM name="pSavePath" />保存路径</param>
public void GetFrames(string pPath, string pSavedPath)
{
Image gif = Image.FromFile(pPath);
FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
//获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
int count = gif.GetFrameCount(fd);
//以Jpeg格式保存各帧
for (int i = 0; i < count; i++)
{
gif.SelectActiveFrame(fd, i);
gif.Save(pSavedPath + "\\frame_" + i + ".jpg", ImageFormat.Jpeg);
}
}
/// <summary><SUMMARY></SUMMARY>
/// 获取图片缩略图
/// </summary>
/// <param name="pPath"><PARAM name="pPath" />图片路径</param>
/// <param name="pSavePath"><PARAM name="pSavePath" />保存路径</param>
/// <param name="pWidth"><PARAM name="pWidth" />缩略图宽度</param>
/// <param name="pHeight"><PARAM name="pHeight" />缩略图高度</param>
/// <param name="pFormat"><PARAM name="pFormat" />保存格式,通常可以是jpeg</param>
public void GetSmaller(string pPath, string pSavedPath, int pWidth, int pHeight)
{
try
{
Image smallerImg;
Image originalImg = Image.FromFile(pPath);
Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
smallerImg = originalImg.GetThumbnailImage(pWidth, pHeight, callback, IntPtr.Zero);
smallerImg.Save(pSavedPath + "\\smaller.jpg", ImageFormat.Jpeg);
}
catch (Exception x)
{
//
}
}
/// <summary><SUMMARY></SUMMARY>
/// 获取图片指定部分
/// </summary>
/// <param name="pPath"><PARAM name="pPath" />图片路径</param>
/// <param name="pSavePath"><PARAM name="pSavePath" />保存路径</param>
/// <param name="pPartStartPointX"><PARAM name="pPartStartPointX" />目标图片开始绘制处的坐标X值(通常为)</param>
/// <param name="pPartStartPointY"><PARAM name="pPartStartPointY" />目标图片开始绘制处的坐标Y值(通常为)</param>
/// <param name="pPartWidth"><PARAM name="pPartWidth" />目标图片的宽度</param>
/// <param name="pPartHeight"><PARAM name="pPartHeight" />目标图片的高度</param>
/// <param name="pOrigStartPointX"><PARAM name="pOrigStartPointX" />原始图片开始截取处的坐标X值</param>
/// <param name="pOrigStartPointY"><PARAM name="pOrigStartPointY" />原始图片开始截取处的坐标Y值</param>
/// <param name="pFormat"><PARAM name="pFormat" />保存格式,通常可以是jpeg</param>
public void GetPart(string pPath, string pSavedPath, int pPartStartPointX, int pPartStartPointY, int pPartWidth, int pPartHeight, int pOrigStartPointX, int pOrigStartPointY)
{
Image originalImg = Image.FromFile(pPath);
Bitmap partImg = new Bitmap(pPartWidth, pPartHeight);
Graphics graphics = Graphics.FromImage(partImg);
Rectangle destRect = new Rectangle(new Point(pPartStartPointX, pPartStartPointY), new Size(pPartWidth, pPartHeight));//目标位置
Rectangle origRect = new Rectangle(new Point(pOrigStartPointX, pOrigStartPointY), new Size(pPartWidth, pPartHeight));//原图位置(默认从原图中截取的图片大小等于目标图片的大小)
graphics.DrawImage(originalImg, destRect, origRect, GraphicsUnit.Pixel);
partImg.Save(pSavedPath + "\\part.jpg", ImageFormat.Jpeg);
}
public bool ThumbnailCallback()
{
return false;
}
}
希望对你有所帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询