Results 1 to 13 of 13

Thread: Save Picturebox (with Lines and label) to bmp

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    14

    Question Save Picturebox (with Lines and label) to bmp

    Hi,

    My application has a requirement where I plot a hugh diagram on picturebox based on some data-analysis.
    This diagram is drawn by creating Line, label and command button controls on runtime and placing them on picture box. The contents of picture box are not really picture as I really act on the events recvd from label and command buttons.

    Now my problem is that when I try to save this image to bmp file I don't get all the contents correctly.
    Effectively I'm not able to capture all the contents of PictureBox correctly. I'm using BitBlt to this.

    So pls enlighten me on what is the best way to do this?

    Thanks in advance
    Mandeep

  2. #2
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: Save Picturebox (with Lines and label) to bmp

    Try this:

    SavePicture Picture1.Image, "C:\TestPic.bmp"
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  3. #3
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Save Picturebox (with Lines and label) to bmp

    If you also want to grab some controls sitting on top of the picturebox (say, Pic1), place an invisible picturebox on the form with the autoredraw and autosize properties set to true (call it Pic2) and then get a screenshot of the desktop and place the relevant part (contents of Pic1) on Pic2. Thereafter, save the contents of Pic2 to hard disk.

    In the code below I'm using TwipsX and TwipsY because the dimensions must be in pixels and the example I've copied the code from had them in twips.
    VB Code:
    1. TwipsX = Screen.TwipsPerPixelX
    2.         TwipsY = Screen.TwipsPerPixelY
    3.         ret = GetDC(GetDesktopWindow)
    4.         BitBlt Pic2.hDC, 0, 0, Pic1.Width / TwipsX, Pic1.Height / TwipsY, ret, _
    5.         (Me.Left + Pic1.Left) / TwipsX, (Me.Height - Me.ScaleHeight + Pic1.Top) / TwipsY, SRCCOPY
    6.         SavePicture Me.Pic2.Image, FileName
    Last edited by krtxmrtz; Apr 11th, 2005 at 06:18 AM.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    14

    Re: Save Picturebox (with Lines and label) to bmp

    Thanks for "quick" reply guys.

    Well let me elaborate the problem. Assume I'm using pic1 to draw the image or diagram.
    My PIC1 has autoredraw and autosize set to true, because its hugh picture even bigger than screen dimension. So I have placed scrollbars around it for user to view it fully.

    Now when I try to do bitblt this hDC to another PIC2, I don't get full picture.
    Pls see attached JPG file. You can easily see distortion in image caused by other controls present on the form.

    So tell some way by which only the contents of PictureBox can be saved into a image or image file.

    -Mandeep
    Attached Images Attached Images  

  5. #5
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Save Picturebox (with Lines and label) to bmp

    Quote Originally Posted by ceo_nikka
    Now when I try to do bitblt this hDC to another PIC2, I don't get full picture.
    Pls see attached JPG file. You can easily see distortion in image caused by other controls present on the form.
    Maybe I misunderstood you. From the image you've posted I don't see any controls on the picturebox, only textboxes below. Unless the numbers representing IP addresses are labels...?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    14

    Re: Save Picturebox (with Lines and label) to bmp

    Those lines are Line control and Text is labels.

    As you can see from the image. By BitBlt I'm unable to capture the full picture. Using hDC, I'm able to capture only the portion visible to user and not all the contents of Picturebox.

    -Mandeep

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