Draw color on country (Mapkit) when it is selected - iphone

I want to color the country on selection of the country from a tableView. Can you help me please?

Considering your case, let me give you a heads up that this would require edge detection (so if you haven't done that before, it will take a LONG time), though not lots of it and the following is just one way of approaching this problem:
1) Take out an image context from the map you have.
2) Apply relevant edge detection algorithms in the area you want and use a bright color to differentiate. Note that this way, the inside would not be colored and I can't tell you for sure if that's possible or not.
3) Add that context as a subView on top of the map.
Also take a look at the Quartz 2D programming guide for more tips.
I would suggest something different, though. Keep pre-stored images for all the possibilities and just put a UIImageView with that as its image in front of the map - this will save you a lot of headache.

Related

detect coordinates of some element on image

Please tell me how to solve this problem.
Where to start and which way to go.
I have an image with some buttons :
How can i detect coordinates of blue round button for example?
The difficulty lies in the fact that these are not application buttons, but just a picture on the desktop.
I understand that this is a vast and complex question, but tell me at least the right way.
It will be useful to many people.
The first thing I can imagine is to do a desktop screen, and then try to detect pixels with blue color.
You don't need to do manual image detection because Apple's vision framework already does this. You can use it to detect rectangular regions, detect text, or recognize and image within an image, depending on your needs.
See Detecting Objects in Still Images

Dragging/Resizing a UIImage on the Device

I'd like to allow a user to add a shape (which would just be a UIImage) onto some sort of canvas, then move and resize it on the screen but I'm not sure how to go about this. Ideally I'd like the basics of a drawing app which can use images from a user's device. Each shape would have an associated position, size and z-index.
The only thing I'm unsure of is how I'd create a bounding box (the one with four blue dots to allow resizing/moving). I have experience with UIKit, and would prefer to keep the majority of the app in this for the time being, but I get the feeling this type of thing might be better suited to Cocos2D or a similar framework.
If anyone has any pointers/open source code I can dig through it would be hugely appreciated.
I think you should look into CALayer, or even CAShapeLayer. I'm just starting to play with them, but I'm pretty sure you can easily get the functionality you want with either. Draw the border in the layer's drawLayer:inContext:. Check out the Quartz2d Guide path drawing section for the functions you need.

UIGesture recognition on different areas of a UIImageView

I have this image:
What I want to do is to add a UITapGestureRecognizer to this image (or I can split the image in the different parts it consists of and add for each part a UITapGestureRecognizer) in order to have different actions according to the leaf tapped. If I split the image in different images each for each leaf the UIImageViews will probably overlap and tapping on one will be recognized as a tap on another one. Having just one image implies knowing the points of the screen that belongs to a leaf rather than to another one.
Any clues on how to do it would be really appreciated.
Thanks
Change your behavior by examining the gesture recognizer's locationInView:.
If you handle the image as one unit, implement this in your gesture recognizer call back to decide which "leaf" (if any) was tapped.
If you handle the image as multiple images, you could also implement it in your callback, or you could also implement in, e.g., your delegate's gestureRecognizerShouldBegin: to suppress events for touches outside the leaf as drawn.
EDIT: I didn't realize that you might also be looking for assistance on figuring out whether a point lies within a leaf. #PhillipMills is correct on this point: we need to know how you are drawing the image.
FOLLOW-UP: This is somewhat outside my area of expertise.
The easiest approach (from a hit-testing standpoint) is to do what #PhillipMills suggested, using Quartz drawing and CGPathContainsPoint(). If you have detailed graphics that you need rendered as a PNG, you could certainly construct a simple path that would be (virtually) overlayed to allow hit testing.
Your other options, AFAIK, are to do hit testing mathematically, but you would basically be reimplementing CGPathContainsPoint() but without a path, or to employ various tricks that look at the color of the pixels at your touch point to do hit testing. Googling will turn up some useful results if you go this route, but honestly for a shape as simple as what you've drawn, just use some UIBezierPath code to recreate in code.
Not sure if this will be helpful but if you get stuck on figuring out which leaf was clicked, you could use an old image map trick we used to use in CD-ROM projects for pixel accurate click tracking on images.
You have your full size image. Make a 25% (or less) scaled version of it. Fill each of the leaf regions you want to track clicks on with a different color; anything you want to ignore make black. When the full size image is clicked, get the x/y coordinates and scale them by the percentage of your scaled image. Then get the pixel color of the scaled image at the scaled x/y coordinate. By determining the pixel color you will know which leaf was clicked.
Sounds clunky but it works really well and is fast.
(all that said, I don't think alpha areas of images trigger the gesture recognizer - so breaking the image up would be less complicated/code intensive.)
If you can break the shape apart into the constituent elements, then you can put each into it's own layer and use the method discussed in this stackoverflow discussion to determine which was touched: Hit Testing with CALayer using the alpha properties of the CALayer contents

Defining regions in an image

Being a complete noob in iPhone development, I was wondering what would be the best way to define regions in an Image (for interaction ). So far I've got 2 ideas :
use CGpath to basically draw the areas that I`m interested in but I quickly can see it becoming tedious on complex graphics .
use a Color coded layer with regions containing different RGB values and return those as my regions .
Are those sensible approaches ?
Depends on what you mean by interaction and whether you want the regions to be visible to the user.
A simple approach would be to just add UIButton's above your image. They can be transparent and any size (rectangular) that you like. Or they can contain images or colors to be visible to the user.
If you need arbitrary shapes then this solution won't be useful to you.

iphone app developement: How to manipulate a selected area of an image?

The function I need to implement is like this:
1> select an small area of an image. This small area could be various shape, not only rectangle.
2> manipulate this area. for example: blurring
Is there any way to do it?
Thanks.
You've got your work cut out for you. Here is one way to do it. Make the selection. Whether you do it with CG paths, or some other way, you want to take the selected image, and make all the unselected area have an alpha of zero. YOu can accomplish this with blendmodes.
Then get the pixel data. See: http://developer.apple.com/mac/library/qa/qa2007/qa1509.html
Then you go through the data and anywhere where your alpha isn't zero, you average the pixel with the pixel one before it, one after it, one above it, and one below it. Of course there are many different ways to blur and this is a poor man's routine.