Results 1 to 6 of 6

Thread: Image and panel (RESOLVED)

  1. #1

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322

    Image and panel (RESOLVED)

    Hi,

    I'm a complete newbee to vb.Net.
    I have a form with a panel.
    That panel displays an image.
    On top of this panel I have a picturebox that 'highlights' a part of the image.
    I'm using drag and drop to position the picturebox on the panel-image.

    This is working (needs some debugging, but hey I'm a newbee :-) )

    Here comes the question:
    Now I want this image in my picturebox to be displayed in another picturbox on my form, so the user can see the final result of his action. And of course be able to save it.

    How do I achieve this?
    Last edited by mvrp350; Jul 31st, 2003 at 09:21 AM.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    if you have an image in a picturebox , you can put it in another picturebox and save it quite easily , here's an example :
    VB Code:
    1. With PictureBox2
    2.             .Image = PictureBox1.Image
    3.             .Image.Save("D:\someimage.jpg")
    4.         End With
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    I understand, but the image in my picturebox isn't an actual image, it's background is set to transparent.
    Basicly it's the a portion of my panel your looking at.

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you would have to get the rectangle area of your " virtual image " ( the first picturebox's image of the panel ) then create an actuall image of it , here's an example of creating an image from a dimension :
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim bmp As New Bitmap(100, 100) ' /// the area of your picturebox's virtual image ( ie: the tab's image area ).
    3.         Dim g As Graphics = Graphics.FromImage(bmp)
    4.         Dim rct As New Rectangle(0, 0, bmp.Width, bmp.Height)
    5.  
    6.         g.FillRectangle(New SolidBrush(Color.Red), rct)
    7.         g.Save()
    8.         g.Dispose()
    9.         With PictureBox2
    10.             .Image = bmp
    11.             .Image.Save("D:\someimage.jpg")
    12.         End With
    13.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    It works, but for 50% ;-)
    it only draw a red rectangle on my screen, not the desired image.
    I've tried to resolve this, but I didn't manage.

    Any help please

  6. #6

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    A few modifications and it works

    VB Code:
    1. Dim newBitmap As Bitmap = Nothing
    2. Dim g1 As Graphics = Nothing
    3.  
    4. newBitmap = New Bitmap(thePic1.Width, thePic1.Height, PixelFormat.Format32bppArgb)
    5. g1 = Graphics.FromImage(newBitmap)
    6. g1.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, thePic1.Width, thePic1.Height))
    7.  
    8. DrawImageRectRect2(g1)
    9.  
    10. g1.Save()
    11. g1.Dispose()
    12. With PictureBox1
    13.     .Image = newBitmap
    14.     .Refresh()
    15. End With
    16.  
    17. '------------------------------------------------
    18.  
    19. Public Sub DrawImageRectRect2(ByRef g1 As Graphics)
    20.  
    21. ' Create image.
    22. Dim newImage As Image = pnlBackground.BackgroundImage
    23. ' Create rectangle for displaying image.
    24. Dim destRect As New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height)
    25. ' Create rectangle for source image.
    26. Dim srcRect As New Rectangle(thePic1.Left, thePic1.Top, thePic1.Width, thePic1.Height)
    27. Dim units As GraphicsUnit = GraphicsUnit.Pixel
    28. ' Draw image to screen.
    29. g1.DrawImage(newImage, destRect, srcRect, units)
    30.  
    31. End Sub

    thePic1 = the picturebox that shows my target
    PictureBox1 = the destination of my image

    Kind regards

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