Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using System.Drawing to graph 9 ellipses. First problem how do you initialize "PaintEventArgs" in Default.aspx. Second problem is if first problem does not solve it then what is wrong with my code?


C#
protected void Page_Load(object sender, PaintEventArgs e)
{
        ...
        using (Bitmap xPanel = new Bitmap(50, 50))
        {
            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/gif;base64," + Imgbase64;
                objGraphicPanel.Dispose();
            }
            xPanel.Dispose();
        }


What I have tried:

I tried to insert an "F" after each data XYecl[k,nn] and ZYecl[k,nn] but I could not figure that out.
Posted
Updated 6-Jun-16 9:44am

1 solution

The Load event[^] doesn't take a PaintEventArgs; it takes an EventArgs.

Since you're not using the argument anywhere, just change the method signature to:
C#
protected void Page_Load(object sender, EventArgs e)
{
    ...
}
 
Share this answer
 
Comments
Member 11242200 6-Jun-16 16:01pm    
Even with just "EventArgs" this code does not produce a graph.
Richard Deeming 6-Jun-16 16:04pm    
Well, you've saved the image as a PNG, but told the browser it's a GIF.

Try using the correct MIME type:
MyImage.Src = "data:image/png;base64," + Imgbase64;

If it still doesn't work, you'll need to debug your code to see what it is drawing. I can't do that for you, because I can't see the data in your variables.
Member 11242200 6-Jun-16 16:23pm    
<img ID="MyImage" runat="server" /> Does this need a src?
Richard Deeming 7-Jun-16 7:13am    
You're setting the src in the code-behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900