xPanel.Save(ms,System.Drawing.Imaging.ImageFormat.Png);应该保存在内存流ms中,绘制的每一行显示9个省略号。在下面没有输出png只是一个objGraphicPanel.FillRectangle屏幕。 缺少的是" F"在PointF x1中,y1,x2和y2是单个浮点数。
protected void Page_Load(object sender, EventArgs e)
{
...
using (Bitmap xPanel = new Bitmap(500, 500))
{
using (Graphics objGraphicPanel = Graphics.FromImage(xPanel))
{
//Background White
SolidBrush whiteBrush = new SolidBrush(Color.White);
objGraphicPanel.FillRectangle(whiteBrush, 0, 0, 200, 200);
Pen colorPen = new Pen(Color.Black, 2);
MemoryStream ms = new MemoryStream();
for (k = 1; k <= 9; k++)
{
for (int nn = 2; nn <= n; nn++)
{
float x1 = Convert.ToSingle(XYecl[k, nn - 1]);
float y1 = Convert.ToSingle(ZYecl[k, nn - 1]);
float x2 = Convert.ToSingle(XYecl[k, nn]);
float y2 = Convert.ToSingle(ZYecl[k, nn]);
PointF[] ptf =
{
new PointF(x1, y1),
new PointF(x2, y2)
};
objGraphicPanel.DrawLines(colorPen, ptf);
xPanel.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
}
}
string Imgbase64 = Convert.ToBase64String(ms.ToArray());
MyImage.Src = "data:image/png;base64," + Imgbase64;
objGraphicPanel.Dispose();
}
xPanel.Dispose();
}
<img ID="MyImage" runat="server" />