我只是在使用 c# 在 asp.net 页面上使用 GDI 完成图像创建教程
我的代码在下面
html页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Image1.aspx.cs" Inherits="GDI_1.Image1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image runat="server" ID="img" ImageUrl="Image1.aspx" />
</div>
</form>
</body>
</html>
asp.net page behind code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace GDI_1
{
public partial class Image1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bitmap image = new Bitmap(300, 50);
Graphics g = Graphics.FromImage(image);
g.FillRectangle(Brushes.Red, 1, 1, 298, 48);
Font font = new Font("Impact", 20, FontStyle.Regular);
g.DrawString("test text", font, Brushes.Yellow, 10, 5);
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
image.Dispose();
}
}
}
我的问题是当我编译它并查看它显示的页面时
GIF89a,2�3f���++3+f+�+�+�UU3UfU�U�U���3�f����������3�f����������3� fՙ������3�f������3333f3�3�3�3+3+33+f3+�3+�3+�3U3U33Uf3U�3U�3U�3�3�33�f3� ��3��3��3��3��33�f3��3��3��3�3�33�f3�3��3��3�3�33�f3��3��3��ff3fff ��f�f+f+3f+ff+�f+�f+�fUfU3fUffU�fU�f�f�3f�ff��f��f��f�3f�ff��f�� f��f�f�3f�ff�f��f��f�f�3f�ff��f��f����3�f���̙��+�+3�+f�+ ��+̙
以及所有在 html 标记之前
谢谢