开发者

Shape transformation using Quartz (iOS)

I have to program a drawing tool that should display shapes on a plane. These shapes could either be arbitrary shapes, like an elipse or a cube, or some pictu开发者_高级运维re that would be drawn on the plane.

What I need to do is, using marker points positioned all around these shapes, be able to transform them by moving the markers. So for instance assuming I have four markers positioned at the top, bottom, left and right, I should be able to stretch the shape horizontally by moving the left and right markers.

I can't use geometric properties of the shape (like changing the radius of the ellipse for instance) since I have to be able to do that on arbitrary shapes (like pictures).

I don't have much experience in image manipulation algorithms, can any one give me some hints of where to start ? Eventually best practice to do it good or even a good algorithm to do that ?

I am developing for the iOS platform.


Have you taken a look at the Quartz 2D Programming Guide in the Apple Developer Center?


Here is how you draw onto a UIImage

UIGraphicsBeginImageContext(CGSizeMake(width, height)); 
// do your drawing operations
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

Here's how you can scale that image

UIGraphicsBeginImageContext(CGSizeMake(scaledWidth, scaledHeight)); 
[image drawInRect:CGRectMake(0,0, scaledWidth, scaledHeight)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

You don't have to do it in two steps -- you could just draw each item scaled. That would be better for the non image drawing.

If you need a CGContextRef to draw, you can use this

CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜