Drawing many images inside UIImageView - iphone

i'm looking for a way to draw multiple images (downloaded from a webservice) inside a single uiimageview. So it'd go like i downloaded image #1, and i'd like to draw it inside rect (0,0,100,100) then #2 at (0,100,100,100) etc.
I'd like to then be able to take the entire composition and save it as an image in camera roll.
thanks in advance for help
greetings
peter

Just create a UIView, then add multiple UIImageViews as subviews.
You may use CGImageCreateWithImageInRect to extract an image from the UIView.

Related

Swift: how could I draw lines inside UIImageView?

I use CGContext in a subclass of UIView to draw lines, it works fine when no other views in the ViewController on storyboard. However each time putting in an `UIImageView' with an image, it'd cover parts of the lines.
But I wanna draw several lines inside the UIImageView or inside the image. What should I do?
Would someone help me with it?
You cannot modify the drawing of an image view. If you want lines to appear in an image view, you must modify the image that it contains. Make a new image context, draw the image into it, draw the lines, extract the new image, and assign that image to the image view.

Hide / reveal UIImage based on finger path?

I hope that makes sense. I'll try to explain it.
I have a UIImageView on screen, and am wondering how I can take the area after "drawing" on it with a finger, and remove that section from the UImage, or, create a separate UIImage from the selection.
I'm not looking for code (unless you have it =] ), just an idea of how to go about doing it. If you have tips, I'd be very grateful, thanks.
If I understand your question,
I think I would add a transparent UIView as a subview over the top of the UIImageView. And draw on that. Then you can remove/hide the subview when your done.
you need to create a UIGestureRecognizer with target and a action like -imageIsPressed, in this -imagePressed method you can call something to make the image disappear. I would suggest placing the UIImage into a UIImageView and calling imageview.hidden = YES; to hide the image, and set it back to "NO" once its not held by the finger.
You'd need to implement something that captures the area the user 'selected' (maybe be creating a CGPath. Then you create a CALayer of the size of the imageView. In it you create, draw and fill the captured path with some arbitrary color while leaving the rest transparent. Finally you apply your generated CALayer as a mask to the UIImageView:
imageView.layer.mask = maskLayer;
Hope that gets you started.
For more info on how to draw that custom CALayer pls refer to Quartz Programming Guide
So basically you want to implement freehand erasing of an image? You will need to use core graphics and the various CGContext methods (with blend mode set to clear) to achieve this. There are two approaches, but both start with drawing your image as the first part of drawRect, and then
1) Store your strokes in an array, and stroke all of them over top of the image.
2) Stroke one stroke over the image and then store the resulting image into a UIImage. Use this UIImage as the next image that you draw in drawRect. This one is difficult for undo/redo functionality.
I recently implemented this myself and made the source available here. Basically I used the same methods described here with this change when setting up the graphics context:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);

How can i make multiple customized uiimageview frame in one view?

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

Clipping multiple paths out of UIImage

In my drawRect method I draw a UIImage, eg
[[UIImage imageNamed:#"shape.png"] drawInRect:CGRectMake(50,50,50,50)];
I want to be able to clip multiple shapes out of the shape so the background of the view is shown. I can't seem to get the quartz clipping methods to behave as I want.
Can anyone help push me in the right direction?
Thanks!
I think what you are wanting is to create a mask and apply that to a UIImage. Take a look here: Rounded corners question.

iOS: How to display multiple images dynamiclly in imageview?

Hi I am new to iPhone.
What I need is, have to display only one image in one case, two images in another case like wise and for that I am using a UIImageview with IBOutlet.
How can I display multiple images in single imageview?
Please help me post some code.
Thank you.
An UIImageView can only display one image at a time. You will either have to use several UIImageViews or compose your images into one file before displaying it.
I think you should subviews ot type UIImageView to your main UIImageView.
The "hard" task will be to compute the boundaries of each subview, according to the prefered layout. Use the image property of UIImageView to set the image for each subview (don't worry about resizing, UIImageView will do the work for you)