Results 1 to 6 of 6

Thread: Picture Box Problems

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    33

    Arrow

    I have drawn an image using SetPixelV, unfortunately, it does not do anything to update the .image property, so vb's built in SaveImage method only saves a black picture. Any help? Thanks!

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Make sure you have set the Picture Box's Autoredraw property to True and also make sure you call the Picture Box's Refresh method before using SavePicture, i.e. ....

    Code:
    Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    
    Private Sub Form_Load()
    
        Picture1.AutoRedraw = True
        Picture1.ScaleMode = vbPixels
        
    End Sub
    
    Private Sub Picture1_Click()
        For I = 1 To 1000
            
            Randomize
            
            SetPixelV Picture1.hdc, Rnd * Picture1.ScaleWidth, Rnd * Picture1.ScaleHeight, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
            
         Next I
         
         Picture1.Refresh
         
         SavePicture Picture1.Image, "C:\Pixels.BMP"
         
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    33

    Angry Hmm

    Unfortunately, this does not work. SetPixel's results are erased by refresh and AutoRedraw. I need some way to edit the image property itself, or some other solution.

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    The code I posted works just fine for me.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    You must set the AutoRedraw before you draw anything and Refresh after the job is coplete.
    Correct me if I'm wrong, but it sounds to me that you've set AutoRedraw and Refresh both after?

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Works fine for me too.

    Make sure these are your steps:

    1. Set AutoRedraw to True
    2. Set pixels with SetPixelV
    3. Refresh the picture with .refresh
    4. Save image using built-in code.

    Cheers,
    Sastraxi
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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