求助,画了个折线图,却显示不出来!

pantheon2008 2011-03-04 07:59:45
根据网上的相关文章,我就照葫芦画瓢。


using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;




public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.pic();
}
protected void pic()
{
float[] shuzu = new float[] { 0f, 0.6328f, 1f };
float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
int m = shuzu.Length;
int[] shuzuint = new int[m];
int[] shuzuint2 = new int[m];
for (int i = 0; i < m; i++)
{
shuzuint[i] = (int)(shuzu[i]*300);
shuzuint2[i] = (int)(shuzu2[i] * 300);
}
Bitmap img = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(img);

g.Clear(Color.Blue);
Pen Blp = new Pen(Color.Blue);
Pen Bp = new Pen(Color.Black);
Pen Rp = new Pen(Color.Red);

Pen Sp = new Pen(Color.Silver);
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
g.DrawLine(Bp, 10, 10, 10, 310);
g.DrawLine(Bp, 10, 310, 310, 310);
Point[] p = new Point[m];
for (int i = 0; i < m; i++)
{
p[i].X = 10+shuzuint[i];
p[i].Y = 310-shuzuint2[i];
}

g.DrawLines(Blp, p);

g.Dispose();
img.Dispose();



}
只有3个点,数组提供横纵坐标。

在浏览器中查看却什么的显示不出来啊?求各位专家指正!
...全文
1625 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
pantheon2008 2011-03-05
  • 打赏
  • 举报
回复
感谢啊,写的非常好啊,我把代码复制过来以后,就显示出来了。谢谢大家,正在认真学习并尝试修改中......

ycproc 2011-03-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 huangwenquan123 的回复:]
C# code

//额,你画完没有让它在浏览器显示啊,加上那两句!
g.DrawLines(Blp, p);
img.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.ContentType = "image/jpeg";
g.Dispose();
……
[/Quote]
+1
gggscfaii 2011-03-04
  • 打赏
  • 举报
回复
不要使用GDI画图,除了IE浏览器,其它浏览器并不支持....
HolyPlace 2011-03-04
  • 打赏
  • 举报
回复
Response.ContentType = "image/gif";
bitImage.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
dsjoy 2011-03-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 huangwenquan123 的回复:]
C# code

//额,你画完没有让它在浏览器显示啊,加上那两句!
g.DrawLines(Blp, p);
img.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.ContentType = "image/jpeg";
g.Dispose();
……
[/Quote]
是的,只画完了,但是没有显示出来。
huangwenquan123 2011-03-04
  • 打赏
  • 举报
回复

//额,你画完没有让它在浏览器显示啊,加上那两句!
g.DrawLines(Blp, p);
img.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.ContentType = "image/jpeg";
g.Dispose();
img.Dispose();
wuyq11 2011-03-04
  • 打赏
  • 举报
回复
if(!IsPostback)this.pic();
zedgraph,mscart,vml都可实现
暖枫无敌 2011-03-04
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
pic();
}

}

public void pic()
{
float[] shuzu = new float[] { 0f, 0.6328f, 1f };
float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
int m = shuzu.Length;
int[] shuzuint = new int[m];
int[] shuzuint2 = new int[m];
for (int i = 0; i < m; i++)
{
shuzuint[i] = (int)(shuzu[i]*300);
shuzuint2[i] = (int)(shuzu2[i] * 300);
}
Bitmap img = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(img);

g.Clear(Color.Blue);
Pen Blp = new Pen(Color.Blue);
Pen Bp = new Pen(Color.Black);
Pen Rp = new Pen(Color.Red);

Pen Sp = new Pen(Color.Silver);
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
g.DrawLine(Bp, 10, 10, 10, 310);
g.DrawLine(Bp, 10, 310, 310, 310);
Point[] p = new Point[m];
for (int i = 0; i < m; i++)
{
p[i].X = 10+shuzuint[i];
p[i].Y = 310-shuzuint2[i];
}
g.DrawLines(Blp, p);
g.Dispose();
img.Dispose();
}
  • 打赏
  • 举报
回复
Jack2013tong 2011-03-04
  • 打赏
  • 举报
回复
g.DrawLines(Blp, p);
g.Dispose();
没看很明白,觉得这地方有问题
// g.Dispose();试试
pantheon2008 2011-03-04
  • 打赏
  • 举报
回复
我用的Visual studio 2010 不是用的iis,用的VS2010自带的那个。刚才试了下,

Response.ContentType = "img/gif";

这句弄的,虽然我不明白但是改成了
img.Save(Response.OutputStream, ImageFormat.Jpeg);

Response.ContentType = "Iamge/Jpeg";
就出来了,但是好景不长。因为这句

float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
错了,赋予了错误的坐标,改成

float[] shuzu2 = new float[] { 0f, 0.4923f, 1f };
这下好了,图片变成了红× ,本人晕了。
huangwenquan123 2011-03-04
  • 打赏
  • 举报
回复
没有什么问题
lz在iis上浏览的?
分析:
这种错误是由asp.net 帐户没有在iis注册造成的。原因可能是.net framework 2.0 先于iis安装了,或者卸载重装了iis。

解决方案:
在开始运行内输入"cmd“进入DOS提示符命令窗口,进入如“C:\WINDOWS\Microsoft.NET\Framework \v2.0.50727”目录,然后运行aspnet_regiis.exe /i 命令,会提示asp.net正在安装,安装完成后就可以正常运作了

huangwenquan123 2011-03-04
  • 打赏
  • 举报
回复
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Default2.aspx" alt="简单折线图" />
</div>
</form>
</body>
</html>

    protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)

this.pic();
}
protected void pic()
{
float[] shuzu = new float[] { 0f, 0.6328f, 1f };
float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
int m = shuzu.Length;
int[] shuzuint = new int[m];
int[] shuzuint2 = new int[m];
for (int i = 0; i < m; i++)
{
shuzuint[i] = (int)(shuzu[i] * 300);
shuzuint2[i] = (int)(shuzu2[i] * 300);
}
Bitmap img = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.Blue);
Pen Blp = new Pen(Color.Blue);
Pen Bp = new Pen(Color.Black);
Pen Rp = new Pen(Color.Red);
Pen Sp = new Pen(Color.Silver);
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
g.DrawLine(Bp, 10, 10, 10, 310);
g.DrawLine(Bp, 10, 310, 310, 310);
Point[] p = new Point[m];
for (int i = 0; i < m; i++)
{
p[i].X = 10 + shuzuint[i];
p[i].Y = 310 - shuzuint2[i];
}
g.DrawLines(Blp, p);
img.Save(Response.OutputStream, ImageFormat.Gif);
Response.ContentType = "img/gif";
Response.Flush();
Response.End();
g.Dispose();
img.Dispose();
}
pantheon2008 2011-03-04
  • 打赏
  • 举报
回复
改成了这样还是报错。请大家给看看啊。论文快交了,还没有弄完......

无法显示 XML 页。
无法查看使用 样式表的 XML 输入。请更正错误然后单击 刷新 按钮,或稍后重试。


--------------------------------------------------------------------------------

文本内容中发现无效字符。处理资源 'http://localhost:1800/WebSite7/Default5.aspx' 时出错。第 1 行,位置: 7

GIF89a





using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;




public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)

this.pic();
}
protected void pic()
{
float[] shuzu = new float[] { 0f, 0.6328f, 1f };
float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
int m = shuzu.Length;
int[] shuzuint = new int[m];
int[] shuzuint2 = new int[m];
for (int i = 0; i < m; i++)
{
shuzuint[i] = (int)(shuzu[i]*300);
shuzuint2[i] = (int)(shuzu2[i] * 300);
}
Bitmap img = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.Blue);
Pen Blp = new Pen(Color.Blue);
Pen Bp = new Pen(Color.Black);
Pen Rp = new Pen(Color.Red);
Pen Sp = new Pen(Color.Silver);
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
g.DrawLine(Bp, 10, 10, 10, 310);
g.DrawLine(Bp, 10, 310, 310, 310);
Point[] p = new Point[m];
for (int i = 0; i < m; i++)
{
p[i].X = 10+shuzuint[i];
p[i].Y = 310-shuzuint2[i];
}

g.DrawLines(Blp, p);

img.Save(Response.OutputStream, ImageFormat.Gif);
Response.ContentType = "img/gif";
Response.Flush();
Response.End();

g.Dispose();
img.Dispose();



}


}


前台的代码


<%@ Page Language="C#" Debug ="true" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

<!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>
<style type="text/css">
.style1
{
width: 100%;
height: 46px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>

<table class="style1">
<tr>
<td>
</td>
<td>
 </td>
</tr>
<tr>
<td>
 </td>
<td>
 </td>
</tr>
</table>

</div>
<img src="Default5.aspx" alt="简单折线图" />
</form>
</body>
</html>




pantheon2008 2011-03-04
  • 打赏
  • 举报
回复
谢谢大家的回答,个人感觉好像是还没有显示的缘故,正在学习领教中.....

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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