开发者

asp:can i enable user to draw a line in webform

开发者 https://www.devze.com 2023-04-12 13:19 出处:网络
is there a way to program in asp c# to enable user draw shapes (line,reqta开发者_如何转开发ngle) on the page

is there a way to program in asp c# to enable user draw shapes (line,reqta开发者_如何转开发ngle) on the page I am wrking on drawing project in asp c#.


Yes you can generate on fly the graphics using have to use System.Drawing API. You can also use SGV (Scalable Vector Graphics) standard - Build Flexible, Lightweight XML-Based Images for ASP.NET Using Scalable Vector Graphics


The namespace of system.Drawing provides the access to basic GDI+ graphic function. In the namespace of System.Drawing.Drawing2D, System.Drawing.Imaging and System.Drawing.Text , .Net provides more advanced functionalities.

using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;  

Create canvas and fill the background

Bitmap  objBitmap;  
Graphics  objGraphics; 

objBitmap  =  new  Bitmap(400,  440);  
objGraphics  =  Graphics.FromImage(objBitmap);   
objGraphics.Clear(Color.White);  

Draw the pie and fill

Pen p=new Pen(Color.Yellow,0);
Rectangle rect=new Rectangle(10,10,280,280);
objGraphics.DrawEllipse(p,rect);

Brush b1=new SolidBrush(Color.Red);
Brush b2=new SolidBrush(Color.Green);
Brush b3=new SolidBrush(Color.Blue);
objGraphics.FillPie(b1, rect, 0f, 60f);
objGraphics.FillPie(b2, rect, 60f, 150f);
objGraphics.FillPie(b3, rect, 210f, 150f); 

Draw font

FontFamily fontfml = new FontFamily(GenericFontFamilies.Serif);
Font font = new Font(fontfml, 16);
SolidBrush brush = new SolidBrush(Color.Blue);
objGraphics.DrawString("Drawing Graphics", font, brush, 70, 300); 

Export and save to picture

objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg); 

End drawing

objBitmap.Dispose();
objGraphics.Dispose();

Here is the refrence: http://programmingdiscussions.blogspot.com/2010/07/aspnet-graphics-tutorial.html

http://www.developerfusion.com/article/2569/creating-images-on-the-fly-with-aspnet/

http://www.c-sharpcorner.com/UploadFile/steve_hall/drawinglinechart02072007053420AM/drawinglinechart.aspx

Hope this helps.


maybe it will be easier to draw in client side with the canvas element, see html5 canvas


Try this javascript library, which you add to your page and allows the user to create shapes etc.

http://www.draw2d.org/draw2d/about


Yes, you can draw shapes. See the following code as sample. More on this link also refer to this namespace

private void Page_Load(object sender, System.EventArgs e) 
{ 
        // Put user code to initialize the page here 
        Bitmap objBitmap = new Bitmap(500, 500); 
        Graphics objGraphics = Graphics.FromImage(objBitmap);  
        objGraphics.Clear(Color.White); 
        objGraphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 400, 1); 
        objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg); 
}

EDIT:

You can use the Paint event handler of a control (ex: Image) to draw a line

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号