现在我要实现的是画流程图。可是实现的时候出现问题。比如同时画两个图,可是运行时是只能画出第一个图。我的代码如下:
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)
{
//画椭圆形代码
}
}
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)
{
//画椭圆形代码
}
}
你的意思是把上面的话改成:
image.Save("diamond.jpg",ImageFormat.Jpeg);吗??“and draw into it, then write it into Response”这句话我怎么实现呢。。
"you should create a bitmap in the memory"
我怎么写到内存。我刚用image.Save("diamond.jpg",ImageFormat.Jpeg);出错了。
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有关呀。。
在一个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();
}