CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    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

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  3. #3
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Stretching an Image to fit an irregular shape

    Cheers M8, will do....

  4. #4
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    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

  5. #5
    Join Date
    Dec 2002
    Posts
    305

    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
  •  





Click Here to Expand Forum to Full Width

Featured