get subImage from image [closed] - ios

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have following image,
from that I need to use separate images like below.
I don't know which kind of functionalities can be work here.
I don't want to just crop that image from photoshop or anything like that. I know there is some way to achieve this. But don't know how to get sub-image.
I've searched somewhere long ago but now can't find the way.
could you please help me to get this.
I've already visited here.

Swift 4
If I understood correctly you would want something like this:
[YOUR_FIRST_IMAGE]
let image = UIImage(named: "[YOUR_FIRST_IMAGE]")
let fromRect = CGRect(x:[OFFSET_HERE], y:0,width:[WIDTH_OF_EACH_ICON],height:[HEIGHT_OF_EACH_ICON])
let croppedImageFromRect = image?.cgImage!.cropping(to: fromRect)
let dottedCircleGreenImage = UIImage(cgImage: croppedImageFromRect!)
imageView.image = dottedCircleGreenImage
To select a different sub image from this collection ([YOUR_FIRST_IMAGE]) you have to offset the x (in the CGRect) with the width of each icon multiplied by the position of image you want minus 1.
For example to select the fifth one: . Get the width of a single icon than multiply it by 5.
Notes:
imageView in the above example is some outlet or form of reference to a UIImageView in a view.
force unwrapping variables is not a good practise, this is just per example.

Related

Limit view movement to a circular area [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to setup a custom color picker. I have setup a circular image with a picker bug. But, I want the bug to only move over the image (there are no colours outside the image), or, another way, only in the circle of the image size.
How can I limit the bug position?
I understand that you want to keep your picker inside the circle image.
To do that just simply grab center point (p1) of your circle image and center point (p2) of currnet position of the picker. Calculate distans between both:
float distance = sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
And if the distance is more that circle radius stop move your picker:
if(distance <= radius)
return YES;// Let the picker move, it's inside the circle image
else
return NO; // Picker outside the circle image
Hope this is what you are about.

is it possible to make custom shaped buttons in iOS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Or some kind of UI objects that can
interact with users
be drawn into any shape, for example, oval.
yes. It is pretty simple.
UIImage *buttonImage = [UIImage imageNamed:#"greenButton.png"];
UIImage *buttonImageHighlight = [UIImage imageNamed:#"greenButtonHighlight.png"];
[myCustomButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[myCustomButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];
It is possible to do it in a variety of ways. Rydgaze gave you the option for using a UIImage as your custom button. If you are looking for a code only way then I would suggest UIBezierPath. UIBezierPath allow's you to draw any shape that you want as well as customize the look. With UIBezierPath I could draw a star and fill it with anything that I would like.
Here is the link to the Reference: https://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html
The idea is that you create a view class. In that view's drawRect method you will design whatever shape you are looking to create and customize it to what you see fit. For you button you would set its self.view to be the view that of your custom UIBezierPath class. That will just draw your custom shape as the button.
The advantage's to writing your button's in code are that it will for one be faster. It also takes up significantly less size because it isn't storing an image file. Also you are able to continue the customization of your shape. That mean's you could change the color, dimensions, etc. very easily.

Adding two images and make one [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new programming IOS app , and I got into this problem : I have two images in the app that I want to post in twitter , but Twitter just accept one picture to be uploaded , so I came out with the idea to make Image A + Image B just One Image. I already have the posting and resizing the images process done. However, I need help to make Image A + Image B just one Image. Anyone can HELP? Thank you.
Here is some code you can use...
Assumptions:
You have your two images already initialized
The two images have the same dimension. If your images have different sizes you'll have to play around with the dimensions yourself.
UIImage *girl1 = INITIALIZE_HERE;
UIImage *girl2 = INITIALIZE_HERE;
// Get the size of your images (assumed to be the same)
CGSize size = [girl1 size];
// Create a graphic context that you can draw to. You can change the size of the
// graphics context (your 'canvas') by modifying the parameters inside the
// CGSizeMake function.
UIGraphicsBeginImageContextWithOptions(CGSizeMake(size.width*2, size.height), NO, 0);
// Draw the first image to your newly created graphic context
[girl1 drawAtPoint:CGPointMake(0,0)];
// Draw your second image to your graphic context
[girl2 drawAtPoint:CGPointMake(size.width,0)];
// Get the new image from the graphic context
UIImage *theOneImage = UIGraphicsGetImageFromCurrentImageContext();
// Get rid of the graphic context
UIGraphicsEndImageContext();
Hope this helps!

How to detect if an image is square? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am making a desktop image editing software using Processing. It will allow the user to select the image to edit. The area in which the user can do the editing is a fixed 640 x 480 screen.
This means that I will have to scale the input image to fit the screen. That is easy to do with rectangular images. The problem arises when dealing with square images.
Programatically, 2500x2501 is not a square image. For all practical purposes it is.
How do I make sure that I properly scale these images ?
Calculate the aspect ratio (width / height, or vice-versa). I suggest dividing whichever is smaller by the other one, so you always get a number that is no greater than one.
Then define a threshold, as a number between 0 and 1. If the resulting division gives a result smaller than the threshold, you can consider the image a non-square.
Something along these lines...
var ratio = 1;
if(Height>Width)
{
ratio = (Height / Width);
}else{
ratio = (Width / Height);
}
var ThresHoldVal = 0.1; // 10% out.
if((Ratio-1) > ThresholdVal)
{
//Invalid.
}

Custom Marker icon Google Maps iOS with image in image? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I try to create many markers in map with icon is a png image like placeholder.
After that i want to set an other image inside of each placeholder.
It looks like this.
My problem is how to set image inside image of marker.
How to do that?
You would need to write code which takes the background image (eg the frame) and adds on the sub-image (eg the food picture), to create a combined UIImage. Then you could use the combined UIImage as the marker's icon.
Check out these questions for some examples of how to draw 2 UIImage objects into a single UIImage:
Draw another image on a UIImage
Attempting to draw image on top of another image using a touch event

Resources