Results 1 to 10 of 10

Thread: DrawImage question [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330

    DrawImage question [RESOLVED]

    Hi Everybody,

    I have an form (frmMain) with an picturebox (pctMap) on wich I draw an image (pctPion.Image). I'm using this to draw the Pion on the Map:

    VB Code:
    1. Dim gr As Graphics = pctMap.CreateGraphics
    2. gr.DrawImage(pctPion.Image, 42, 42)

    But this can only be done in the frmMain code... I've got an class Map wich should do this... How can this be solved? Is it an design error by me !

    Extra question: instead of pctPion.Image i would like to use an filename is this possible cause when I try that I get an error?!

    Thnx in advance,

    Bloged
    Last edited by Bloged; Mar 12th, 2004 at 04:37 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    1-I don't quite get what you mean !

    2-It's working . What does the error say ?
    VB Code:
    1. Me.PictureBox1.Image = New Bitmap("c:\test.jpg")

  3. #3

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330
    VB Code:
    1. Dim gr As Graphics = pctMap.CreateGraphics
    2. gr.DrawImage(pctPion.Image, 42, 42)

    This is what I use to draw an image over an image... pctPion.Image over the image of pctMap... now I want to use something like:
    VB Code:
    1. gr.DrawImage(c:\test.gif, 42 ,42)
    But that won't work...

    Also, more important, now this function is in the frmMain code (frmMain also holds the pctMap & pctPion) but I want this function in the Map class so simple said it would look something like this:
    VB Code:
    1. Dim gr As Graphics = frmMain.pctMap.CreateGraphics
    2. gr.DrawImage(frmMain.pctPion.Image, 42, 42)
    But that doesn't work!

    Anyone who knows the answers (and gets what I'm trying to say)

    Thnx in advance

    Bloged

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Do you have any problems using this way :
    VB Code:
    1. gr.DrawImage(New Bitmap("c:\test.gif"), 42, 42)
    I still don't know what you mean by "map class" ? Do you mean referencing mainform in your class to use it inside the function?

  5. #5

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330
    This works:
    VB Code:
    1. gr.DrawImage(New Bitmap("c:\test.gif"), 42, 42)

    By Map class I mean I've got an class called Map:
    VB Code:
    1. Public Class Map
    2. End Class

    This class is for my form containing the pctMap on wich I want to draw the test.gif
    VB Code:
    1. Public Class frmMain
    2. End Class

    How can I do that?

    Hope this clarifies it more!

    Grtz,

    Bloged

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    You'll have to pass as argument or your picture or its graphic's pbject
    \m/\m/

  7. #7

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330
    Originally posted by PT Exorcist
    You'll have to pass as argument or your picture or its graphic's pbject
    Could you explain with some sample code? I'm pretty new to VB .Net

    Grtz,

    Bloged

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Public Class mytestclass
    2.  
    3.     Public Shared Sub DrawingSub(ByVal frm As Form, ByVal picBox As PictureBox)
    4.         Dim gr As Graphics = frm.CreateGraphics
    5.         gr.DrawImage(picBox.Image, 42, 42)
    6.     End Sub
    7. End Class
    8.  
    9.  
    10.  
    11. 'then you just call it from your main form as this :
    12. mytestclass.DrawingSub(Form1, PictureBox1)

  9. #9

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330
    Ok that seems to be it now I've got to test it!

    But I get:
    'frmMain' is a type and cannot be used as an expression

    Sorry real newbie in VB.Net
    Edit:
    I solved it myself this seems to work:
    VB Code:
    1. Public Shared Sub DrawPion(ByVal pctBox As PictureBox)
    2.    Dim gr As Graphics = pctBox.CreateGraphics
    3.    gr.DrawImage(New Bitmap("c:\pion.gif"), 42, 42)
    4. End Sub

    Called with:
    VB Code:
    1. Map.DrawPion(pctMap)

    Grtz,

    Bloged
    Last edited by Bloged; Mar 12th, 2004 at 04:20 PM.

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Bloged
    Ok that seems to be it now I've got to test it!

    But I get:
    'frmMain' is a type and cannot be used as an expression

    Sorry real newbie in VB.Net
    I don't understand why you got that error !!! I used it that and working ok

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width