rotating image in quartz 2d - iphone

i want to rotate image in quartz 2d around one corner..i want to make analog clock.

You should probably start with the Quartz 2D Programming Guide. In particular, check out the section on transforms, this covers rotation.
Essentially what you need to do is apply a transform matrix for rotation to the Current Transform Matrix (CTM). This defines the mapping of the coordinates that you draw to and the coordinates that are displayed on the user's device.
Quartz does make this all fairly straightforward to do in code; the link above has example code.

For example, you could do something like :
CGAffineTransform transform = CGAffineTransformMakeRotation(ANGLE_IN_RADIANS);
view.transform = transform;
And if you want a smoother animation, try using an UIView Animation.
But if you need an other rotation, you should check the documentation :-)
Good Luck !

Related

iOS Quartz 2D: draw an image simulating y axis rotation?

I want to do this:
draw an image using Quartz 2D, the image look like rotated according to its y axis in a 3D space, like this:
Is Quartz 2D capable to do this?
No, you cannot do this directly with Quartz 2D. It supports only affine transformations, which always preserve parallel lines.
(It's clear that you want the parallel lines on the top and bottom edges of your figure to become non-parallel.)
The term you're looking for is "perspective transformation", if you want to search for other ways to achieve this result.
I don't know how to do it in 2d, but its really easy to do it with quartz using this kind of call:
yourView.layer.transform = CATransform3DMakeRotation(M_PI/4, 0.0, 0.0, 1.0);
You should look into using the CATransform3D's. They are pretty powerful and easy to call.

Is there any open source sdk like cam scanner in iphone sdk [duplicate]

I am stuck in my application feature. I want cropping feature similar to Cam Scanner Cropping.
The screens of CAM-SCANNER are:
I have created similar crop view.
I have obtained CGPoint of four corners.
But How can I obtained cropped image in slant.
Please provide me some suggestions if possible.
This is a perspective transform problem. In this case they are plotting a 3D projection in a 2D plane.
As, the first image has selection corners in quadrilateral shape and when you transform it in a rectangular shape, then you will either need to add more pixel information(interpolation) or remove some pixels.
So now actual problem is to add additional pixel information to cropped image and project it to generate second image. It can be implemented in various ways:
<> you can implement it by your own by applying perspective tranformation matrix with interpolation.
<> you can use OpenGL .
<> you can use OpenCV.
.. and there are many more ways to implement it.
I had solved this problem using OpenCV. Following functions in OpenCV will help you to achieve this.
cvPerspectiveTransform
cvWarpPerspective
First function will calculate transformation matrix using source and destination projection coordinates. In your case src array will have values from CGPoint for all the corners. And dest will have rectangular projection points for example {(0,0)(200,0)(200,150)(0,150)}.
Once you get transformation matrix you will need to pass it to second function. you can visit this thread.
There may be few other alternatives to OpenCV library, but it has good collection of image processing algorithms.
iOS application with opencv library is available at eosgarden.
I see 2 possibilities. The first is to calculate a transformation matrix that slants the image, and installing it in the CATransform3D property of your view's layer.
That would be simple, assuming you knew how to form the transformation matrix that did the stretching. I've never learned how to construct transformation matrixes that stretch or skew images, so I can't be of any help. I'd suggest googling transformation matrixes and stretching/skewing.
The other way would be to turn the part of the image you are cropping into an OpenGL texture and map the texture onto your output. The actual texture drawing part of that would be easy, but there are about 1000 kilos of OpenGL setup to do, and a whole lot to learning in order to get anything done at all. If you want to pursue that route, I'd suggest searching for simple 2D texture examples using the new iOS 5 GLKit.
Using the code given in Link : http://www.hive05.com/2008/11/crop-an-image-using-the-iphone-sdk/
Instead of using CGRect and CGContextClipToRect Try using CGContextEOClip OR CGContextClosePath
Though i havnt tried this... But i have tried drawing closed path using CGContextClosePath on TouchesBegan and TouchesMoved and TouchesEnd events.
Hope this can give more insight to your problem...

Cropping UIImage like camscanner

I am stuck in my application feature. I want cropping feature similar to Cam Scanner Cropping.
The screens of CAM-SCANNER are:
I have created similar crop view.
I have obtained CGPoint of four corners.
But How can I obtained cropped image in slant.
Please provide me some suggestions if possible.
This is a perspective transform problem. In this case they are plotting a 3D projection in a 2D plane.
As, the first image has selection corners in quadrilateral shape and when you transform it in a rectangular shape, then you will either need to add more pixel information(interpolation) or remove some pixels.
So now actual problem is to add additional pixel information to cropped image and project it to generate second image. It can be implemented in various ways:
<> you can implement it by your own by applying perspective tranformation matrix with interpolation.
<> you can use OpenGL .
<> you can use OpenCV.
.. and there are many more ways to implement it.
I had solved this problem using OpenCV. Following functions in OpenCV will help you to achieve this.
cvPerspectiveTransform
cvWarpPerspective
First function will calculate transformation matrix using source and destination projection coordinates. In your case src array will have values from CGPoint for all the corners. And dest will have rectangular projection points for example {(0,0)(200,0)(200,150)(0,150)}.
Once you get transformation matrix you will need to pass it to second function. you can visit this thread.
There may be few other alternatives to OpenCV library, but it has good collection of image processing algorithms.
iOS application with opencv library is available at eosgarden.
I see 2 possibilities. The first is to calculate a transformation matrix that slants the image, and installing it in the CATransform3D property of your view's layer.
That would be simple, assuming you knew how to form the transformation matrix that did the stretching. I've never learned how to construct transformation matrixes that stretch or skew images, so I can't be of any help. I'd suggest googling transformation matrixes and stretching/skewing.
The other way would be to turn the part of the image you are cropping into an OpenGL texture and map the texture onto your output. The actual texture drawing part of that would be easy, but there are about 1000 kilos of OpenGL setup to do, and a whole lot to learning in order to get anything done at all. If you want to pursue that route, I'd suggest searching for simple 2D texture examples using the new iOS 5 GLKit.
Using the code given in Link : http://www.hive05.com/2008/11/crop-an-image-using-the-iphone-sdk/
Instead of using CGRect and CGContextClipToRect Try using CGContextEOClip OR CGContextClosePath
Though i havnt tried this... But i have tried drawing closed path using CGContextClosePath on TouchesBegan and TouchesMoved and TouchesEnd events.
Hope this can give more insight to your problem...

Analog clock using CALayers

I'm trying to make an analog clock for the iPhone, in which the clock hands will automatically update to the current time. I also want the clock hands to be images, unlike this: http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html. What would be the easiest way to create this using CALayers to rotate the images/hands?
There are two properties of CALayers that may be of interest to you - the anchorPoint and the transform. Set the anchor point at the origin around which you want to rotate the images, calculate the angle of rotation, make a transformation matrix from it (using CATransform3DMakeRotation around the appropriate axis) and set the transform on the layer.
It's all explained in detail here.

Image stretching

I want Stretch a image. For that i use sprite. I want stretch sprite & this stretching is may be Circular or curve animation. I don't understand what methode used for that. Can anyone help me?
Since you tagged your question with cocos2d I guess you'll be using that. It's really basic to strech an image
Sprite *mySprite = [Sprite spriteWithFile:#"mysprite.png"];
mySprite.position = ccp(100, 100);
mySprite.scale = 2.0;
[self addChild:mySprite];
If you want to animate it you can use the cocos2d actions or just create your own animation. The example below does a linear animation to 3x original sprite size in 1 second:
id action1 = [ScaleTo actionWithDuration:1.0 scale:3.0];
[mySprite runAction: action1];
For manipulating views and images in general in ways such as streching you can read up on transforms provided by the sdk, you can learn about 2D transforms here http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html and you can extend that further to 3D by manipulating the layers transforms instead of the views transforms. Youll be able to do things such as scaling and rotating and you can define your own transforms as well. This example project http://developer.apple.com/iphone/library/samplecode/MoveMe/ is a good reference to get started with transforms and animating them.