I want to add an image onto another image. But I know that imageview has a rectangular frame. Is there a way I can add an image without rect farme? Say, I want to add a pin onto an imageview. will it necessarily be a rectangular shaped imageview or can I add an image with frame shape that of a pin.
It is rectangular you can not add imgeView with other shape.
What you need is an transparent png that is your pin and added it to your original image view like an sub view.
Related
I want to add a Pinch and Pan gesture that will crop the UIImage views on my ViewController. To crop the images, just pinch/pan the appropriate image and it will resize.
I currently have the Take Pic and Choose Image buttons grab the appropriate images into the UIImageView boxes accordingly, but I want to be able to pinch and pan to size and crop the image in the view.
I want the box to stay fixed at its current size, and the image within will be the one resizing and cropping.
PS. I am using storyboard
Here is a screenshot of what I have.
http://i.stack.imgur.com/chkk5.png
I was thinking that the right direction would be to add a swipe and pan gesture to each uiimageviews in storyboard, but not sure what to do after.
My general strategy for this in the past has to been place the UIImageView inside another UIView (in order to clip it) and add a UIPinchGestureRecognizer and a UIPanGestureRecognizer to the parent UIView. When you receive events for either of these you apply the appropriate transformation to the transform property of the UIImageView.
When scaling, for example, you would do the following:
-(void)scale:(UIPinchGestureRecognizer*)pinch
{
float scale = pinch.scale;
imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
pinch.scale = 1;
}
The final step of reseting the scale is important because you are simply scaling the existing transform each time rather than a base identity transform. You should find that you will be able to handle translating the transform by using a UIPanGestureRecognizer and its translationInView: method (remember you will also have to reset this with setTranslationInView:CGPointZero.
Finally, in order to get a cropped/clipped UIImage out you can either capture the view's contents (I believe the transform property is only respected on iOS 7+) or alternatively render the UIImage into a CGContextRef, and using the same transform to transform the CGContextRef.
You can use below link...
Crop image
Is it possible for a user to draw a dotted line (in a circle) around the bit of the UIImageView they wish to crop to, and then for the UIImageView to resize to those points? It's a bit like the lasso/marquee effect in Photoshop:
Update: Since iOS 8.x, UIImageView provides a maskView property. Just prepare an image with some opaque pixels, create another image view with that mask image, and set this mask image view as the maskView. The opaque pixels in the mask image will be the ones shown in the underlying image.
UIImageView *maskView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"somemask"]];
maskView.frame = imageView.bounds;
imageView.maskView = maskView;
// imageView will be masked by maskView
.
Original Answer
There's quite a bit to do, but here's a high-level outline:
create an empty image which will become a mask
build a path in that image from user input
fill the path to turn it into a mask
apply the mask to the imageview's image
Create image: A simple idea here is to just ship a black image with your project. It should be sized to match the maximum region a user can select. Read the image into memory (UIImage imageNamed:) and set it up as the drawing context by calling UIGraphicsBeginImageContext.
Create path: (see apple docs). When the user starts stroking the region, call CGContextBeginPath, then follow user gestures, sampling the touches and adding small segments by calling CGContextMoveToPoint repeatedly as touchesMoved.
Create mask: To turn the path into a mask you want a black background and the path filled with white. If you started with a black image, you just need to do the fill. See the same apple guide about doing that.
Finally, you'll apply this mask to your imageView's image. Here's a decent reference for that.
This answers just one part of your question i suppose, but here's an example on how to draw and animate the dotted line (i.e. marching ants effect).
I have to make view where there will be multiple curved or irregular shaped imageview. Now when i will touch a UIImageview then it will import image from photo gallery.For example: Suppose
I have an UIView with background image.
On that view i have 3 irregular shaped UIImageview.every UIImageview is attached with each other.
Now suppose i have touch in the first UIImageview then it will take an image from photo gallery.
When i have imported the image then that image will be as the background image of the UIImageview.
I have to make sure that if my UIImageviewis smaller then its background image then i will able to move the image or rotate the image or scale or zoom the image to adjust the image according to the size of UIImageview.
How can i do that whole process??? any help by link,source code,tutorial or anything else will be cordially appreciable.
Basically my first priority is that how can i make those irregular shaped UIImageView pro-grammatically.
IF ANY FURTHER QUERY TO ASK THEN PLEASE DON'T HESITATE.
Thanks In Advance
The one way of doing this is as follows:
Subclass from UIImageView set touchesBegan methods for each UIImageView for import image, setting on background and whatever you want to do on touch.
What does 'attached' mean? If all of them should move together, then, again, you have to deal with it in touchesBegan methods, sending messages like 'Hey views, i've moved on this vector:[vector], please do it too'.
In pt. 3.2 i didn't get your point. :( You can set in UIImageView subclass self.contentMode = UIViewContentModeScaleAspectFit or UIViewContentModeScaleToFill, so its image will always fit the view.
About irregular shape, did you read links below? I suppose there's not an super easy way to do it :(
http://www.iphonedevsdk.com/forum/iphone-sdk-development/76923-hittest-collision-for-irregular-shaped-uiviews.html
Draggable UIImageView Partially Transparent & Irregular Shaped
Simple way of using irregular shaped buttons
I am placing a vertical image into a square UIImageView. It gets centered inside the square. Does UIImageView have a method to shift its contained image to the right or left?
I suppose you could try:
imageView.contentMode = UIViewContentModeLeft;
Otherwise I would recommend just putting the image view where you want it.
I have an imageView with contentMode UIViewContentModeScaleAspectFit. So it resizes the image without changing the aspect ratio. But the image inside the imageview is horizontally and vertically centred.
I don't want it to be vertically centred. How can I move this image to the upper end of imageview?
I think you should make a custom UIView in which you can have UIImage property (just like UIImageView has) and you need to over ride 'drawRect' method of UIView and draw the image at appropriate position using [image drawInRect:rect]; method, check the documentation you will find stuff about aspect ratio as well while drawing...
In UIImageView, image's x,y position can't be changed..