Results 1 to 11 of 11

Thread: [RESOLVED] Picturebox and resizing

  1. #1

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Resolved [RESOLVED] Picturebox and resizing

    Hi. I am having trouble with something I think should be fairly simple to fix.

    I have a picturebox (its size doesn't matter).

    I use pSet to randomly draw yellow pixels in it.

    Let's say I end up having a square of 2 x 2 yellow pixels (VERY SMALL), I would then like the picturebox to be resized to exactly fits the pixels I've drawn into it.

    The picturebox scalemode is set to pixels, and the autoredraw method doesn't seem to resize the picture box at all (it only does when I load up a .bmp in it).

    I thought that "picLetter.width = 2" would have worked because the scalemode is in pixels.. but it doesn't.

    VB Code:
    1. picLetter.AutoRedraw = True
    2.     picLetter.ScaleMode = vbPixels

    Any tips?
    Chris

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Picturebox and resizing

    When you create the points, create a small checker, and if the current point, X or Y, is larger than a preset value, change it. Then, when you're done plotting points, resize based on those numbers.

  3. #3

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Picturebox and resizing

    If I understand right... Instead of trying to reduce the picturebox size, you're suggesting to start with a very small picturebox and GROW it when drawing pixels to it?

    Sounds fair. I could make my picture box 0 width and 0 height. But now let's say I add a pixel at 1,1.. How do I resize that picture box by only 1 pixel? Even tho scalemode is set to pixel, I don't think I'm mastering those techniques..

    Thanks for your quick reply.
    Chris

  4. #4
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Picturebox and resizing

    No, I'm suggesting exactly what you want... start with a picture box, pick a set of random numbers that are within it, then resize the picture box to the highest coordinates of the points within the box. Look at this code for an example. Form needs a picture box(duh), two labels and a command button.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     Dim MaxX As Integer
    4.     Dim MaxY As Integer
    5.    
    6.     Dim HighX As Integer
    7.     Dim HighY As Integer
    8.    
    9.     Dim tempX As Integer
    10.     Dim tempY As Integer
    11.    
    12.     Dim counter As Integer
    13.  
    14.     Label1.Caption = "Starting Size: " & Picture1.ScaleWidth & ", " & Picture1.ScaleHeight
    15.    
    16.     MaxX = Picture1.ScaleWidth
    17.     MaxY = Picture1.ScaleHeight
    18.    
    19.     For counter = 1 To 500 'change this to however many points you want plotted
    20.         tempX = Int(Rnd * MaxX)
    21.         tempY = Int(Rnd * MaxY)
    22.         Picture1.PSet (tempX, tempY), vbYellow
    23.         If tempX > HighX Then HighX = tempX
    24.         If tempY > HighY Then HighY = tempY
    25.     Next counter
    26.    
    27.     Picture1.Width = (HighX * 15)
    28.     Picture1.Height = (HighY * 15)
    29.    
    30.     Label2.Caption = "Final Size: " & Picture1.ScaleWidth & ", " & Picture1.ScaleHeight
    31.  
    32. End Sub

  5. #5
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Picturebox and resizing

    Well, that's the basic idea, anyway. There's a bit of a flaw with the resizing that I'm trying to pin down... bit of a booger, too...

  6. #6

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Picturebox and resizing

    Thanks for your help.

    Those 2 lines are what I needed:

    Picture1.Width = (HighX * 15)
    Picture1.Height = (HighY * 15)
    Chris

  7. #7
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: [RESOLVED] Picturebox and resizing

    Which are incorrect statements... substitute them with these:

    VB Code:
    1. Picture1.Width = Picture1.Width - ((MaxX - HighX) * 15)
    2.     Picture1.Height = Picture1.Height - ((MaxY - HighY) * 15)

    That will give you an accurate resizing based on where the points landed.

  8. #8

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: [RESOLVED] Picturebox and resizing

    Okay. I had this part modified already. Thanks. Also, I replaced "15" by Screen.TwipsPerPixelX or Screen.TwipsPerPixelY, which seems to give the same result. Is this good practice?
    Chris

  9. #9

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: [RESOLVED] Picturebox and resizing

    One more thing. Now that my picturebox is resized how I want it to, I am doing the following:

    SavePicture picLetter.Image, "c:\test\LetterMask.bmp"

    The size of LetterMask.bmp is not, for example, 4 x 10 (which is the size of the picturebox AFTER resizing)... It is still using the size of the original picturebox size when I first executed the form (80 x 290).

    Any idea? In other words I need the savepicture to act on the visible part (after resizing) of the pciturebox only.

    Thanks
    Chris

  10. #10
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: [RESOLVED] Picturebox and resizing

    I don't think you can save good images after using PSet... I believe it's the SetPixel or SetPixelV API that you need... but I've only had passing experience with that. I know chemicalNova did a bit of that with me, so I'll yell at him when I see him.. unless someone else can answer your question. I'd take the "Resolved" out of the thread title, if yo still have questions.

  11. #11

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: [RESOLVED] Picturebox and resizing

    Actually I think I might just have solved that problem. I made the picturebox original size 1,1 (or smallest possible). Then when I know my X,Y coordinates of my yellow pixels, I make the picturebox grow. It saves my file right, using a small 2k or 4k (dendant on my pixels emplacements) instead of a static 69k file.

    I'm happy with this. Thanks.
    Chris

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