|
-
May 17th, 2005, 01:35 PM
#1
Really Struggling
Hi Guy's
Still really Struggling with this, what I would like to do is draw a freehand shape and instead of filling it with a colour, I would like to fill it with an image. However I also want the image to be stretched to fit the shape its being pasted into.
Can anybody point me in the right direction of code examples or know how to do this, really desperate now....
Thankyou in advance...
Ken
PS: Cheers HannestheGreat for previous threads....
-
May 17th, 2005, 02:08 PM
#2
Re: Really Struggling
First thing that comes to mind is to use MoveToEx, BeginPath, LineTo, EndPath, and PathToRegion. Then use SelectClipRgn to prevent drawing outside the shape, and StretchBlt (don't forget SetStretchBltMode) to draw your image. You will find example code for these functions on allapi.net.
Hope that helps you out. Let us know...
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 17th, 2005, 02:32 PM
#3
Re: Really Struggling
Cheers WizBang
Any idea what terminology I should be using to search the web for vb examples, not really coming up with much when I try searching as not sure what this method is called etc....
thanks again
-
May 17th, 2005, 04:56 PM
#4
Re: Really Struggling
Searching for the API calls I mentioned should turn up some stuff. Examples won't likely be exactly what you are looking to do, but you should be able to see how to apply the methods. Besides this site, allapi and PlanetSourceCode.com are good places to look, though often times Google will be your best bet.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 18th, 2005, 09:43 AM
#5
Re: Really Struggling
Hi wizBang,
Ok, I've managed to do the MovtoEX and LineTo API's to draw an irregular shape and even fill it in with black, but spent all day trying to work out how to stretch an image to fit inside it.
This is my failed attempt after I've drawn the shape ;
Code:
'Close the path bracket
Retval = EndPath(Me.hdc)
'Convert the bracket to a region
hRgn = PathToRegion(Me.hdc)
'Fill the region
Retval = PaintRgn(Me.hdc, hRgn)
'Select the Clip Region
Retval = SelectClipRgn(me.hdc, hRgn)
SetStretchBltMode Me.hdc, 4
Dim W As Long, H As Long
W = Picture1.Width / Screen.TwipsPerPixelX
H = Picture1.Height / Screen.TwipsPerPixelY
StretchBlt Me.hdc, 0, 0, W * 2, H * 2, Picture1.hdc, 0, 0, W, H, SRCCOPY
Picture1 holds the Picture I want to paste to fit the shape I've drawn.
Can you help ?
really REALLY appreciate your help....
Last edited by Judgey; May 18th, 2005 at 10:12 AM.
-
May 18th, 2005, 02:37 PM
#6
Re: Really Struggling
It depends on what you want as a result. Specifically, do you want the image to be large enough to fill the entire region, even if parts of the image get clipped in order to fit the shape? Or, do you want the image to be in its original proportions, only sized so that all of it fits within the shape without clipping any of the edges?
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 18th, 2005, 05:10 PM
#7
Re: Really Struggling
Hi Wizbang,
I actually want the image to be stretched and squashed out of proportion according the the edges of the irregular shape, similar to if you were to draw a picture on a balloon and then inflate it the image would be stretched out of proportion, only more complicated with mine as the shape could be anything.
Cheers
Ken
-
May 18th, 2005, 05:45 PM
#8
Re: Really Struggling
 Originally Posted by Judgey
Hi Wizbang,
I actually want the image to be stretched and squashed out of proportion according the the edges of the irregular shape, similar to if you were to draw a picture on a balloon and then inflate it the image would be stretched out of proportion, only more complicated with mine as the shape could be anything.
Oh Boy!
Now that's not gonna be easy. I'm thinking that you'd end up relying on DirectDraw, OpenGL, or something like that.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 19th, 2005, 03:10 AM
#9
Re: Really Struggling
Hi Wizbang, 
Ok, how about simplifying things down a bit, if the irregular shape becomes a shape with only 4 corners, eg, Square or rectangle which can be either skewed or given a perspective shape.
Would it then be possible to take a standard square/rectangle image and mould it to one of the above shapes ?
ALSO :
I have another idea, how I can copy pixel by pixel from one image to another, what I was thinking of was finding the centre point of the shape and then centre point of the source image, calculate how many pixels to the top of the source image and then copy each pixel, divide the space from the centre point to the edge of the shape by number of pixels and then place each pixel in the shape at these steps, something along these lines ?
Cheers
Ken
Last edited by Judgey; May 19th, 2005 at 03:15 AM.
-
May 19th, 2005, 01:19 PM
#10
Re: Really Struggling
There's no need to calculate pixel-by-pixel. Using StretchBlt will render the image into any rectangular shape. You just can't use it to push pixels around into shapes like circles, ovals, octagons, trapezoids, or irregular shapes drawn by hand.
So, what you might do is square off the shape first, to make it rectangular. Then StretchBlt the image into it.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
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
|