Results 1 to 5 of 5

Thread: DrawToBitmap not right

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    DrawToBitmap not right

    I am trying to create a screenshot of my geomap object:

    Code:
       Private Function CreateScreenshot(ByVal Control As Control) As Bitmap
    
            Dim Screenshot As New Bitmap(Control.Width, Control.Height)
            Control.DrawToBitmap(Screenshot, New Rectangle(20, ListBox1.Top, 1100, 800))
            Screenshot.Save("WorldMap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            Return Screenshot
    
        End Function
    
            CreateScreenshot(geoMap1)
    Its the worldmap on my form.
    Name:  form.jpg
Views: 131
Size:  21.2 KB

    Whatever I try with sizing the image always turns out like this:

    Name:  WorldMap.jpg
Views: 128
Size:  17.7 KB

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,069

    Re: DrawToBitmap not right

    Try...

    Dim Screenshot As New Bitmap(1100, 800)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,069

    Re: DrawToBitmap not right

    This is also wrong...

    Control.DrawToBitmap(Screenshot, New Rectangle(20, ListBox1.Top, 1100, 800))

    Left and top should both be zero

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,069

    Re: DrawToBitmap not right

    Working any better?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    Re: DrawToBitmap not right

    Quote Originally Posted by .paul. View Post
    Working any better?
    No change, still the same.

    Code:
        Private Function CreateScreenshot(ByVal Control As Control) As Bitmap
    
            Dim Screenshot As New Bitmap(1100, 800)
             Control.DrawToBitmap(Screenshot, New Rectangle(0, 0, 1100, 800))
            Screenshot.Save("WorldMap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            Return Screenshot
    
        End Function

    I can screenshot the whole form with this but its not just the map.

    Code:
            Dim bounds = Me.Bounds
            Using bitmap As New Bitmap(bounds.Width - 15, bounds.Height - 8)
                Using g = Graphics.FromImage(bitmap)
                    g.CopyFromScreen(New Point(bounds.Left + 8, bounds.Top), Point.Empty, bounds.Size)
                End Using
                bitmap.Save("WorldMap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            End Using
    Last edited by clausowitz; May 8th, 2021 at 04:31 AM.

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