现在我要实现的是画流程图。可是实现的时候出现问题。比如同时画两个图,可是运行时是只能画出第一个图。我的代码如下:
webForm1.aspx.cs
private void Page_Load(object sender, System.EventArgs e)
{
IGraphics MyGraphic = null;
IGraphics MyGraphic1 = null;
GraphicsFactory MyGraphicsFactory = new GraphicsFactory();
MyGraphic = MyGraphicsFactory.MakeGraphic("arrowLine",Response);
MyGraphic1 = MyGraphicsFactory.MakeGraphic("ellipse",Response);
}
我只能画出arrowLine,而ellipse却画不出来。我把arrowLine注释掉后面的ellipse就能画出来了。为什么只能画出一个呢。。
画图的类:GraphicsFactory.cs
//图形接口
public interface IGraphics{}
//工厂类
public class GraphicsFactory 

 public IGraphics MakeGraphic(string Name,System.Web.HttpResponse Response) 
 { 
     IGraphics MyGraphic = null; 
   try 
   { 
        Type type = Type.GetType("Paint.Class."+Name);
        MyGraphic = (IGraphics)Activator.CreateInstance(type,new object[]{Response});
   } 
     catch (TypeLoadException e) {throw e;}
     return MyGraphic; 
    } 

//画带箭头的折线
public class arrowLine:IGraphics
{
  public arrowLine(System.Web.HttpResponse Response)
  {
      Bitmap image = new Bitmap(400,400);
      Graphics g = Graphics.FromImage(image);
      g.Clear(System.Drawing.Color.White);
      AdjustableArrowCap myArrow = new AdjustableArrowCap(6,6);
      CustomLineCap customArrow = myArrow;
      Pen capPen = new Pen(Color.Black,1);
      capPen.CustomEndCap = customArrow;
      g.DrawLines(capPen,new Point[]{new Point(10,10),new Point(80,10),new Point(80,160),new Point(10,160)});
      image.Save(Response.OutputStream,ImageFormat.Jpeg);
  }
}
//画椭圆形
public class ellipse:IGraphics
{
  public ellipse(System.Web.HttpResponse Response)
  {
   //画椭圆形代码
  }
}

解决方案 »

  1.   

    >>>> image.Save(Response.OutputStream,ImageFormat.Jpeg);??instead of writing into Response directly, you should create a bitmap in the memory, and draw into it, then write it into Response
      

  2.   

    to: saucer(思归) :
    你的意思是把上面的话改成:
    image.Save("diamond.jpg",ImageFormat.Jpeg);吗??“and draw into it, then write it into Response”这句话我怎么实现呢。。
      

  3.   

    to: saucer(思归) :
    "you should create a bitmap in the memory"
    我怎么写到内存。我刚用image.Save("diamond.jpg",ImageFormat.Jpeg);出错了。
      

  4.   

    no, seehttp://www.4guysfromrolla.com/webtech/090201-1.shtmlhttp://msdn.microsoft.com/msdnmag/issues/02/02/ASPDraw/
      

  5.   

    //画椭圆形
    public class ellipse:IGraphics
    {
       public ellipse(System.Web.HttpResponse Response)
       {
          Bitmap image = new Bitmap(400,400);
          Graphics g = Graphics.FromImage(image);
          g.Clear(System.Drawing.Color.White);
            g.FillEllipse(new SolidBrush(Color.Black),9,19,62,42);
          g.FillEllipse(new SolidBrush(Color.White),10,20,60,40);
          image.Save(Response.OutputStream,ImageFormat.Jpeg);
          image.Dispose();
        }
    }
    TO:思归。我上面的画椭圆。好像和你给我看的那两个页面的方法差不多吧。我是单个图可以画出来。但是我要同时画两个的时候就只能画出第一个图了。。IGraphics MyGraphic = null;
    IGraphics MyGraphic1 = null;
    GraphicsFactory MyGraphicsFactory = new GraphicsFactory();
    MyGraphic = MyGraphicsFactory.MakeGraphic("arrowLine",Response);
    MyGraphic1 = MyGraphicsFactory.MakeGraphic("ellipse",Response);上面是我调用的。是不是和我的那个MyGraphicsFactory有关呀。。
      

  6.   

    别往Response里存2次,也别在你的类(譬如arrowLine)里往Response直接写,而往一个Bitmap里画,到画完了,再把Bitmap一次性地存入Response
      

  7.   

    谢谢思归,我明白了。。
    在一个Bitmap里面画多个图形,最后用Response,现在可以了。多谢。
    public diamond(System.Web.HttpResponse Response)
    {
    Bitmap image = new Bitmap(400,400);
    Graphics g = Graphics.FromImage(image);
    GraphicsPath path=new GraphicsPath();
    path.AddLines(new Point[]{new Point(60,10),new Point(10,40),new Point(60,70),new Point(110,40)});
    path.CloseFigure();
             g.Clear(System.Drawing.Color.White);
    g.DrawPath(Pens.Black,path);
    g.FillEllipse(new SolidBrush(Color.Black),9,19,62,42);
    g.FillEllipse(new SolidBrush(Color.White),10,20,60,40);
    image.Save(Response.OutputStream,ImageFormat.Jpeg);
    image.Dispose();
    g.Dispose();
    }
      

  8.   

    无论如何都是只能画一个的,因为这个操作实际上不是把你画的图输出到客户端显示的页面,而是直接把本次输出作为一次图片输出,但是一次输出仅仅能输出一张图片。如果你要输出两张图片,你就要用一个网页放两个<img>把src指向两个绘图aspx。