zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
Go Back  Xtreme Visual Basic Talk > > > zooming by selecting part of picture in a picturebox


Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2004, 11:08 PM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Unhappy zoom in on selected part of picture in a picturebox


this is what i need to do

make a VB program, with a picture in it, and allow the user to click and drag any part of the picture (with the box where they selected is visible). and when they let go, it will basically take whatever was selected and zoom it to the full box.

i need expert help on this one, i'm a novice at VB. anything will help.

a Thank you in advance to everyone that helps

Last edited by unknown311; 09-01-2004 at 11:43 PM.
Reply With Quote
  #2  
Old 09-02-2004, 08:12 AM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

First, you need to start with making the selection rectangle.
Declare a Point variable in the form declarations.
In the MouseDown event, store the e.X and e.Y that you receive into the Point variable that you declared.
In the MouseUp event, take the e.X and e.Y that you receive here and, combined with the Point you have assigned earlier, create a Rectangle based on these two coordinates. You may want to use Math.Min and Math.Max to make sure that the Rectangle is properly initialized by making sure that the rectangle's Left is the minimum of the two X values and the Right is the maximum of the two X values. Similarly for the Y values and Top / Bottom.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 09-02-2004, 11:16 AM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Question need more explaination

ok, im trying to put all this together. could you give me a little more detail. i'm new to this stuff. please explain a little more. how do i use a point variable?
Reply With Quote
  #4  
Old 09-02-2004, 05:58 PM
bear24rw's Avatar
bear24rw bear24rw is offline
Contributor
 
Join Date: May 2004
Location: NJ
Posts: 477
Default

Code:
Dim pt As Point pt.x = 50 pt.y = 50
that will store the point 50, 50 to 'pt'
__________________
Use[vb][/vb] tags when posting code.
Reply With Quote
  #5  
Old 09-02-2004, 07:17 PM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Talking

i know how to use the point function that way. but i need to know basically how to take the data from the user's click'n'drag so it can show a rectangle as im dragging... then erase it after the user lets off the mouse button, THENNN (lol) take those coordinates and stretch them to the corners of the picture box.... basically cropping the image but only where i want it to.

Quote:
Originally Posted by bear24rw
Code:
Dim pt As Point pt.x = 50 pt.y = 50
that will store the point 50, 50 to 'pt'
Reply With Quote
  #6  
Old 09-02-2004, 11:04 PM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Well, if you have the points already, to get the selection rectangle with the beginning point and the ending point, you do something like this.

Code:
RL = Math.Min(firstpoint.X, lastpoint.X)
RT = Math.Min(firstpoint.Y, lastpoint.Y)
RR = Math.Max(firstpoint.X, lastpoint.X)
RB = Math.Max(firstpoint.Y, lastpoint.Y)

Dim BoundingRect As Rectangle = Rectangle.FromLTRB(RL, RT, RR, RB)
That's how you get the bounding rectangle.

To display the focus rectangle, first, how is the picture being shown in the picturebox?

You need to declare a boolean variable that indicates if the mouse is down.
So, when you declare this variable, you need to set it to True in the MouseDown event, and to False in the MouseUp event.

You will check this variable in the MouseMove event to determine if the mouse is down and, if the mouse is down, draw the Rectangle.

Creating the Rectangle is the same method above of getting the bounding rectangle from the mouse beginning and the mouse end, just being put into action. In the MouseMove event, you should be able to get the .X and the .Y property from the eventargs.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 09-03-2004, 01:07 AM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Default

waw..... well, you know, iceplug, thank you very much man. i guess i just suck at this... im not visualizing how this is all gonna be put together, ONLY because im stressed that i need this by 2moro. i'm gonna keep tryin, my prob is i know what i need to use, i don't know how to use it.
Reply With Quote
  #8  
Old 09-03-2004, 08:13 AM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Well, did you get the data into the firstpoint yet in MouseDown?
Did you try getting the Mouse coordinates in the mouse move and making a finalpt with that?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #9  
Old 09-03-2004, 10:59 AM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Thumbs up

dude, this is what i need right now...could you write the whole code for it, so i can atleast understand what i need to put, and where. because i don't know any of it. i honestly think it would be faster for you to write the code then to keep going back and forth. but i can tell you if you give me the code, i will discuss it if i have any questions. just so you know, its awesome that you help out as much as you do. anyway. thank you for your help. and any help you might give me in the future.
Reply With Quote
  #10  
Old 09-03-2004, 05:53 PM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

We do not write code here. Especially not for a school assignment. Check the posting guidelines. And besides, once you figure out what it is, you'll know so much more about rectangle selection than if I did give you the code (and fix any errors or make changes that you want to make).


I'd be happy to look over what you have and point you in the right direction, though.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #11  
Old 09-07-2004, 11:31 PM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Default

ok. i got as far as creating a picturebox and being able to drag and it will draw the rectangle for me.... the Q is... how am i going to load a picture... and still be able to do that...


i used the picturebox1.creategraphics and then drew a rectangle.
im thinking im going to have to make a picture box in the background and make the first one show wats behind it. but i have NO CLUE how to do that. but i think that would be the best way. or maybe not... oh well
Reply With Quote
  #12  
Old 09-08-2004, 08:27 AM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

No, you should never need a hidden control on a form.
Now, let's see if I understand what you are saying.

You want to take the selection from the picturebox image that you just made and zoom it so that it fills the picturebox, right?

There is a Graphics.DrawImage overload that does this:
GFX.DrawImage(PBox.Image, PBox.GetBounds, selectionrectangle, GraphicsUnit.Pixel)

The first argument is the image you want to draw from.
The second is the rectangle defining where the final picture will be drawn.
The third is the rectangle defining where you want to draw from.
I always use Pixel as the final argument.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #13  
Old 09-08-2004, 02:49 PM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Default

hmmm.... i got the thing to display a rectangle. but when i go down-right, its fine.... but i cant go up after i've drawn that because it like FLOATs up with it. but only after i set a ratio. i also use math.min/max. it works fine without a ratio. how could i get a ratio without it messing up.
Reply With Quote
  #14  
Old 09-08-2004, 10:49 PM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Your rectangle messes up when you move the mouse upwards?

Let me see how you are drawing the rectangle.

And, you are trying to get the ratio that you have zoomed in after you make the rectangle?

ZoomX = PBox.Image.Width / Rec.Width
ZoomY = PBox.Image.Height / Rec.Height
Those are the zoom factors.
The full image ratio would be the reciprocal.
Ratiox = Rec.Width / PBox.Image.Width
Ratioy = Rec.Height / PBox.Image./Height
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #15  
Old 09-09-2004, 12:07 AM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Wink misunderstood

ok, you might have misunderstood me....

right now i can view an image, select a region with the mouse, the rectangle draws itself.... i havent gotten to the actual zooming part yet... anyway, when the rectangle is drawn i keep the rectangle aspect ratio the same as the picture's... BUT when i do so it wont let me CREATE an bottom-left to upper-right rectangle. it wont do anything with (mouse current position) Y values that are smaller than the Y value of ( mouse down) so basically. it will draw the rectangle downward, but (AS im holding) go above the top line ( if ya know what im sayin) it will just RAISE the top line of the rectangle with the cursor..... ALLLLlllll the way to the top of the screen

i use Math.min/max for calculating which should be (top y) (bottom y) ETC.
then i make it draw a rectangle with that.... BUT i also find that ONLY when i keep the aspect ratio , it depends on the X axis for drawing the rectangle, so if i go STRAIGHT DOWN ( zero difference in X) it does nothing

lol.... its really cool effects though, dont get me wrong, but im trying to get this thing working, and its just a pain

thanks again Plug
Reply With Quote
  #16  
Old 09-09-2004, 07:59 AM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

I don't understand.
Quote:
anyway, when the rectangle is drawn i keep the rectangle aspect ratio the same as the picture's...
Are you trying to draw the rectangle with the mouse so that you keep the aspect ratios equal? Other than that, I don't see what aspect ratio has to do with drawing a rectangle.
Quote:
BUT when i do so it wont let me CREATE an bottom-left to upper-right rectangle.
Didn't you just create the rectangle already? You are trying to create another one?
So, you cannot create a second rectangle after you've created the first?

Did you check the values of your firstpoint and lastpoint?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #17  
Old 09-09-2004, 05:46 PM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Smile

lol.... im sorry, i dont mean to confuse you....

im taking this project step by step till i reach the desired outcome. first, i got the picture to load in the box, THEN, i got the rectangle to be drawn by itself in its own form, when i click and drag, it draws a rectangle from the start point to the current. THEN AFTER THAT, i made the rectangle be drawn OVER the picture, by setting the picture as a background and then refreshing after every rectangle. NOW im working on drawing that rectangle by holding down the mouse button, but instead of drawing just ANY rectangle where ever my mouse goes. i want the rectangle that is drawn to have the SAME aspect ratio of the picture loaded. when i do this, by setting the rectangle height equal to the rectangle width times ( * ) the ratio of original picture, it works fine with drawing upper-left to bottom-right rectangles, but it wont draw (atleast not correctly) bottom-right to upper-left rectangles.... but it DOES keep the aspect ratio


i hope that clears some things up for you, and i hope you can further help me with this. and thanks again iceplug
Reply With Quote
  #18  
Old 09-09-2004, 06:40 PM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

So you ARE doing something COMPLETELY different.
Well, how are you trying to keep the aspect ratio?
To make the aspect ratio the same, you'll have to keep the old rectangle and then compute the new rectangle based off of the old rectangle width / height, or the longest/shortest of the width/height. I think most applications do it based on the longer of the width and height.
The aspect ratio rectangle does depend on which side you have started from though, so that might be why yours doesn't work from the bottom-left.

Horiz = Math.Abs(lastpoint.X - firstpoint.X)
Vertiz = Math.Abs(lastpoint.Y - firstpoint.Y) 'Calculate the height and width of our rectangle.

If Vertiz > Horiz Then
'tall rectangle.
T = Math.Min(firstpoint.Y, lastpoint.Y)
B = Math.Max(firstpoint.Y, lastpoint.Y)
If lastpoint.X > firstpoint.X Then 'cursor to the right of the firstpoint.
L = firstpoint.X
R = firstpoint.X + Vertiz * AspectWidth / AspectHeight
Else
R = firstpoint.X
L = firstpoint.X - Vertiz * AspectWidth / AspectHeight
End If
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #19  
Old 09-14-2004, 11:34 PM
unknown311 unknown311 is offline
Newcomer
 
Join Date: Sep 2004
Location: MA, USA
Posts: 13
Smile part of picture

hmmm, i'm encountering a problem drawing just only part of a picture.
what would you suggest to go about that procedure.....

from the rectangle that i select, i want it to redraw it with what i selected stretched to the sides
Reply With Quote
  #20  
Old 09-15-2004, 12:15 AM
Iceplug's Avatar
Iceplugzooming by selecting part of picture in a picturebox Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You only want to draw the picture, right? Not take the resized version and make that a picture, right?

So, you should be able to use the method that I mentioned in a post above:

Quote:
There is a Graphics.DrawImage overload that does this:
GFX.DrawImage(PBox.Image, PBox.GetBounds, selectionrectangle, GraphicsUnit.Pixel)
Where you change the selectionrectangle to whatever rectangle that you have just created.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
 
zooming by selecting part of picture in a picturebox
zooming by selecting part of picture in a picturebox
 
-->