|
-
August 12th, 2005, 04:18 AM
#1
Stretching an Image to fit an irregular shape
Hi Guy's, its been a while but have a problem with an area of VB I've never got into.
What I would like to do is Define a Shape by either drawing freehand or pointing and clicking and drawing a line to the last point clicked to create a shape such as say a 50p piece for example. I then want to load an image and fit it into the inside the defined area so that its stretched to the defined shape, not cropped.
I've seen this done in Paint Shop Pro for example where you can freehand Select and area and then paste an image into that shape and it stretches itself and takes on the shape, sorry if 'm not explaining it correctly but have no idea what the terms used who be.
Anybody any ideas where I can start looking for example code ?
Cheers Guru's
-
August 14th, 2005, 06:27 PM
#2
Re: Stretching an Image to fit an irregular shape
I believe the term is "image warping" or "morphing", and by searching the web you should be able to find both code and mathematical papers.
- petter
-
August 16th, 2005, 03:07 AM
#3
Re: Stretching an Image to fit an irregular shape
-
August 17th, 2005, 06:05 AM
#4
Re: Stretching an Image to fit an irregular shape
Well spent most of the day looking up Image Warping and still not got very far, found some code for vb.net which used the DrawImage function, but it seems you can only select three points, the Top Left, Top Right and bottom left and the function then decides where best to put the fourth.
I want to be able to just draw any shape and then warp the image to fit the shape, to make it easier if I say the shape drawn would always have four points, any ideas ?
Cheers Guys
-
August 17th, 2005, 10:13 AM
#5
Re: Stretching an Image to fit an irregular shape
"I then want to load an image and fit it into the inside the defined area so that its stretched to the defined shape, not cropped."
What you want to do is mapping from image to desired area/shape. Discretize both image and shape into equal number of segments. On the image each segment will be a rectangle, while on the shape, each segment will be of a shape you design. Then develop a functional relationship between each point (pixel) in the image-segment and each point (pixel) in shape-segment. Fill the resulting point (pixel) in the shape-segment with the color from the corresponding point (pixel) on image-segment.
You can try it with some simple shapes - that should tell you the kind of problems that might arise during shrinking from original image (loss of pixels/color) or during expansion from original image (one image-pixel may have to be mapped to more than one shape-pixel).
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
|