We help IT Professionals succeed at work.

Asp.net Graphics.FromImage question

foulkrj
foulkrj asked
on
Hi,
I am just getting started with drawing in ASP.Net 3.5 using VisualStudio 2008.  I need to create floorplan drawings.  I'm having trouble creating the Graphics object to paint on.   I found a good video based done in C# in ASP.Net 2.0 where the Graphics object was created simply using Graphics.FromImage(b) where b is a bitmap object.  I have interpreted the simple code in VB.Net and I am trying to set my Graphics object to Graphics.FromImage(b).  I get the code error "FromImage is not a member of PermitPkg1.aspx.Graphics.  I know this is really simple but I've gone round and round and need some help
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging

Partial Public Class RoomLayout
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'set up graphic object to paint on
        Dim b As New Bitmap(100, 100)
        Dim g As New Graphics
        g = Graphics.FromImage(b)


    End Sub

End Class

Open in new window

Comment
Watch Question

Shahan AyyubSenior Software Engineer

Commented:
try this:

        Dim g As Graphics = Graphics.FromImage(b)

Author

Commented:
Hi Shahan,
This code gave me the error "g is already declared
        Dim b As New Bitmap(100, 100)
        Dim g As New Graphics
        Dim g As Graphics = Graphics.FromImage(b)

This Code gave me Error 'FromImage' is not a member of 'PermitPkg1.aspx.Graphics'.
        Dim b As New Bitmap(100, 100)
        Dim g As Graphics = Graphics.FromImage(b)

This code (with "New" )gave me the error 'End of Statement is expected'
        Dim b As New Bitmap(100, 100)
        Dim g As New Graphics = Graphics.FromImage(b)

Can you think of anything else?
Jim
Senior Software Engineer
Commented:
I told you to to do this:

replace:
       Dim b As New Bitmap(100, 100)
        Dim g As New Graphics
        g = Graphics.FromImage(b)
with:

       Dim b As New Bitmap(100, 100)
        Dim g As Graphics= Graphics.FromImage(b)
Shahan AyyubSenior Software Engineer

Commented:
Could you please clarify :

>>FromImage is not a  member of PermitPkg1.aspx.Graphics


Author

Commented:
Shahan,
PermitPkg1.aspx is the name of the VisualStudio Project.  I know it shouldn't have the ".aspx" in it's name.  I typed it wrong when I started.  Do you think the Project name is my problem?
Thanks,
Jim

Author

Commented:
I renamed the project to PermitPkg1.  It didn't change the actual project file or .sln file name
Shahan AyyubSenior Software Engineer

Commented:
Yes a minor mistake can change the scenario because the code I provided to you is working for me.
Shahan AyyubSenior Software Engineer

Commented:
If this is a test project you showed in question i 'll say to you that make a new project and test the code according to my suggested changing. If you will need I can provide you that also. Since you begin with graphics it might possible that this is not portion of error which you are assuming a wrong code.

Author

Commented:
Thanks, I redid the project with a new name and it ran without error.