Please help with ASP.Net Graphics!

Discussion in 'C#' started by JEP_Dude, Mar 6, 2009.

  1. #1
    Is there a problem with VS.Net 2003? Here's what I have:

    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim Flag As New Bitmap(300, 100)
    Dim X, Y As Integer

    For X = 0 To (Flag.Height - 1)
    For Y = 0 To (Flag.Width - 1)
    Flag.SetPixel(X, Y, Color.Yellow)
    Next Y
    Next X

    For X = 0 To (Flag.Height - 1)
    Flag.SetPixel(X, X, Color.Red)
    Next X

    'PictureBox.AlternateText() = B
    'PictureBox = B
    'PictureBox.ImageAlign = B
    'PictureBox = Flag
    'PictureBox.ImageUrl.flag

    PictureBox.ImageUrl = Flag
    End Sub

    I got this code example directly from the VS.Net help. But it doesn't work! I've tried several different approaches with the "PictureBox" line. All don't display the chart. The compiler claims that it should be "PictureBox.Image = Flag", but that gives an error. Where am I going wrong?

    The second question is what types of controls do I need on the web form and what should they be called?

    Thanks in advance.

    May you have a blessed day.
     
    JEP_Dude, Mar 6, 2009 IP
  2. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #2
    First of all, PictureBox can not be used in ASP.NET form. Instead of it, you need to use Image. However, Image does not work in the same way PictureBox works.
     
    MayurGondaliya, Mar 7, 2009 IP
  3. JEP_Dude

    JEP_Dude Peon

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    MayurGondaliya (and/or anyone with the answer) ....

    I've only been using ASP.Net for a little more than a month now. Thank you for pointing out what I shouldn't do. I'm sorry but I must ask for you to be more specific. I don't understand what corrections I should make. Please feel free to elaborate as much as you'd like.

    Thanks in advance.

    May you have a blessed day.
     
    JEP_Dude, Mar 7, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
  5. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #5
    Here is the sample code for image rendering using C#, ASP.NET, I hope it helps.

    Refer http://ask4asp.net/post/sample-code-for-generaing-bar-charts-using-asp-net-c-sharp.aspx

    System.Drawing.Bitmap b = new System.Drawing.Bitmap(730, 300);
    
                for (int i = 0; i < b.Width; i++)
                {
                    for (int j = 0; j < b.Height; j++)
                    {
                        b.SetPixel(i, j, System.Drawing.Color.FromArgb(216, 216, 216));
                    }
    
                }
                Random rnd = new Random(10);
    
                int BarCount = 0;
    
    
                for (int i = 0; i < b.Width; i++)
                {
                    b.SetPixel(i, 0, System.Drawing.Color.YellowGreen);
                    b.SetPixel(i, 50, System.Drawing.Color.YellowGreen);
                    b.SetPixel(i, 100, System.Drawing.Color.YellowGreen);
                    b.SetPixel(i, 150, System.Drawing.Color.YellowGreen);
                    b.SetPixel(i, 200, System.Drawing.Color.YellowGreen);
                    b.SetPixel(i, 250, System.Drawing.Color.YellowGreen);
    
                }
    
                for (int i = 20; i < b.Width; i = i + 30)
                {
                    BarCount++;
                    if (BarCount == 25)
                    {
                        break;
                    }
                    for (int j = rnd.Next(280); j < b.Height; j++)
                    {
    
                        b.SetPixel(i + 9, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 8, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 7, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 6, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 5, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 4, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 3, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 2, j, System.Drawing.Color.Green);
                        b.SetPixel(i + 1, j, System.Drawing.Color.Green);
                        b.SetPixel(i, j, System.Drawing.Color.Green);
    
    
                    }
    
                }
    
                for (int i = 0; i < 1; i++)
                {
                    for (int j = 0; j < b.Height; j++)
                    {
                        b.SetPixel(i, j, System.Drawing.Color.Black);
                    }
    
                }
                for (int i = 0; i < b.Width; i++)
                {
                    for (int j = b.Height - 1; j < b.Height; j++)
                    {
                        b.SetPixel(i, j, System.Drawing.Color.Black);
                    }
    
                }
    
    
    
                b.Save(Server.MapPath("") + "\\Temp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    
                ImageMap1.ImageUrl = "Temp.jpg";
    Code (markup):
     
    MayurGondaliya, Mar 8, 2009 IP
  6. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #6
    You can't directly assign a bitmap object to the imageurl of an asp.net image control. You will either need to save the bitmap object to a file using the "Save" method of the bitmap object as stated by MayurGondaliya or create an http handler which will create the image
     
    vihutuo, Mar 13, 2009 IP