C# 生成图片 ie显示正常,firefox 不显示

htziyou 2010-11-04 09:26:51
代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ImageMain("1", "15", "", "", "MingLiu", "要生成的字", "c:\\11.jpg"); ;
}

/// <summary>
/// 基本样式处理
/// </summary>
/// <param name="fontnum">艺术字编号</param>
/// <param name="fontsize">字体大小</param>
/// <param name="fontimagesizewith">图片宽</param>
/// <param name="fontimagesizehigh">图片高</param>
/// <param name="fonttype">字体书写类别</param>
/// <param name="fonttxt">字体文本</param>
/// <param name="path">艺术字保存路径</param>
/// <returns>成功返回true失败返回false</returns>
public static bool ImageMain(string fontnum, string fontsize, string fontimagesizewith, string fontimagesizehigh, string fonttype, string fonttxt, string path)
{
bool is_ok = true;
try
{
string wz = fonttxt;
string filePath = path;
Bitmap bmp = new Bitmap(10, 10);
Graphics gs = Graphics.FromImage(bmp);
if (fontimagesizewith == "" || fontimagesizehigh == "")
{
if (fontnum == "6")
{
fontimagesizewith = (Convert.ToInt32(fontsize) * 2 * wz.Length).ToString();
fontimagesizehigh = (Convert.ToInt32(fontsize) * wz.Length).ToString();
}
else
{
fontimagesizewith = (Convert.ToInt32(fontsize) * 2 * wz.Length).ToString();
fontimagesizehigh = (Convert.ToInt32(fontsize) * 4).ToString();
}
}
Rectangle rect = new Rectangle(0, 0, Convert.ToInt32(fontimagesizewith), Convert.ToInt32(fontimagesizehigh));
Metafile mf = new Metafile(filePath, gs.GetHdc(), rect, MetafileFrameUnit.Pixel);
Graphics g = Graphics.FromImage(mf);
//文本样式
Font newFont = new Font(fonttype, Convert.ToInt16(fontsize), FontStyle.Italic);

if (fontnum == "1")
{
Matrix matrix = new Matrix();
//投射
matrix.Shear(-1.5f, 0.0f);
//缩放
matrix.Scale(1, 0.5f);
//平移
matrix.Translate(130, 88);
//对绘图平面实施坐标变换、、
g.Transform = matrix;
//阴影样式
SolidBrush grayBrush = new SolidBrush(Color.Gray);
//正文颜色
SolidBrush colorBrush = new SolidBrush(Color.BlueViolet);
//绘制阴影
g.DrawString(wz, newFont, grayBrush, new PointF(0, 30));
g.ResetTransform();
//绘制前景
g.DrawString(wz, newFont, colorBrush, new PointF(0, 30));
}
g.Save();
g.Dispose();
mf.Dispose();
return is_ok;
}
catch (Exception e)
{
return false;
}
}
}
}

...全文
150 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
van430606 2010-11-04
  • 打赏
  • 举报
回复
/// <summary>
/// 显示内存图像
/// </summary>
/// <param name="msShowStream"></param>
/// <returns></returns>
private void ShowImages(MemoryStream msShowStream)
{
// 從緩衝區資料流清除所有內容輸出。
Response.ClearContent();
// 取得或設定輸出資料流的 HTTP MIME 類型。
Response.ContentType = "Image/Jpeg";
// 將二進位字元的字串寫入 HTTP 輸出資料流。
Response.BinaryWrite(msShowStream.ToArray());
// 將目前所有受緩衝的輸出傳送到用戶端、停止網頁的執行,並引發 EndRequest 事件。
Response.End();
}

直接用Response的方法寫字節流就不會出問題了
gomoku 2010-11-04
  • 打赏
  • 举报
回复
[Quote=引用楼主 htziyou 的回复:]
...
Metafile mf = new Metafile(filePath
...
[/Quote]
Firefox能读EMF格式吗?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧