|
-
Nov 9th, 2006, 11:56 AM
#1
Thread Starter
Hyperactive Member
[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:
picLetter.AutoRedraw = True
picLetter.ScaleMode = vbPixels
Any tips?
-
Nov 9th, 2006, 11:58 AM
#2
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.
-
Nov 9th, 2006, 12:03 PM
#3
Thread Starter
Hyperactive Member
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.
-
Nov 9th, 2006, 12:09 PM
#4
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:
Private Sub Command1_Click()
Dim MaxX As Integer
Dim MaxY As Integer
Dim HighX As Integer
Dim HighY As Integer
Dim tempX As Integer
Dim tempY As Integer
Dim counter As Integer
Label1.Caption = "Starting Size: " & Picture1.ScaleWidth & ", " & Picture1.ScaleHeight
MaxX = Picture1.ScaleWidth
MaxY = Picture1.ScaleHeight
For counter = 1 To 500 'change this to however many points you want plotted
tempX = Int(Rnd * MaxX)
tempY = Int(Rnd * MaxY)
Picture1.PSet (tempX, tempY), vbYellow
If tempX > HighX Then HighX = tempX
If tempY > HighY Then HighY = tempY
Next counter
Picture1.Width = (HighX * 15)
Picture1.Height = (HighY * 15)
Label2.Caption = "Final Size: " & Picture1.ScaleWidth & ", " & Picture1.ScaleHeight
End Sub
-
Nov 9th, 2006, 12:19 PM
#5
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...
-
Nov 9th, 2006, 12:21 PM
#6
Thread Starter
Hyperactive Member
Re: Picturebox and resizing
Thanks for your help.
Those 2 lines are what I needed:
Picture1.Width = (HighX * 15)
Picture1.Height = (HighY * 15)
-
Nov 9th, 2006, 12:23 PM
#7
Re: [RESOLVED] Picturebox and resizing
Which are incorrect statements... substitute them with these:
VB Code:
Picture1.Width = Picture1.Width - ((MaxX - HighX) * 15)
Picture1.Height = Picture1.Height - ((MaxY - HighY) * 15)
That will give you an accurate resizing based on where the points landed.
-
Nov 9th, 2006, 12:30 PM
#8
Thread Starter
Hyperactive Member
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?
-
Nov 9th, 2006, 12:42 PM
#9
Thread Starter
Hyperactive Member
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
-
Nov 9th, 2006, 12:50 PM
#10
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.
-
Nov 9th, 2006, 12:53 PM
#11
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|