UIImageView Increase Brightness in specific area - objective-c

How can I increase brightness in specific area of a UIImageView,
For ex:I have an imageview with image.I want to increase the brightness of image in specific elliptical area of that image.
I know how to increase the brightness of whole image , But dont know for specific elliptical area.

You can add a black UIView with a specific alpha apply on it (this will control how dark you want your view) and attach a mask layer to this view that has an ellipse. For the part of your view that is masked it will be brighter.
You need to import the Quartzcore framework when you are working with layer/mask. The mask is a property of your view layer ([yourView layer].mask).

Related

Completely transparent UIButton with irregular hit area

I know how to use a background image with alpha channel to create a UIButton with an irregular tap area. But with this solution, only the ignore-tap area is transparent; the tap area consists of the opaque.
What I want is a totally transparent UIButton, with an irregular tap area. (It triggers an animation behind the button.)
It seems that some sort of extra UILayer with some hit-testing could work, but I don't quite see how. Suggestions welcome.
Here's my solution. The problem: A UIImageView (call it the base view) to which I want to attach an irregularly-shaped tap area. The area corresponds to something in the image, let's call it a river. It could be a non-connected region.
In the Finder, duplicate the view's image, and make all the non-river pixels transparent, using your favorite graphics app. Call this the mask image.
When the base view is tapped, check to see if the corresponding pixel in the mask image is or is not transparent. (Solution left to reader; examples abound.)
So the mask image is never actually rendered, it is just used as a reference.
Note that if the base view gets resized or moved around (as it does in my app, via animating its constraints) then you have to "move" the mask image too, or in some other way manage the coordinate translation between view and mask. The easiest way to do this is to make the mask image a hidden subview of the base view, with its left, top, leading and trailing anchors constrained to be equal to those of the base view. Then they move around together, and the coord translation between the two is the identity.
I wrapped all this up in a subclass of UIImageView so that it manages its own mask, and calls a delegate if the "river" (or whatever) is tapped.

How to change UITableViewCell Image to Circle in UITableView if width and height are different

My code is
imv.clipsToBounds=YES;
imv.layer.cornerRadius=imv.frame.size.width/2;
imv.layer.borderWidth = 4.0;
The best solution would be to either resize your image view to be square (using autolayout or manually set the frame) or even better you could redraw the image using an image context with a circular clipping mask, then you wouldn't have performance problems on older devices because of corner radii that you recompute on scrolling.
Something like here https://stackoverflow.com/a/17722702/384309

How can I trim a UIImageView to fit an aspect ratio image

I am using a crop tool in my app and I need to modify a UIImageView so that it fits an image exactly after inserting the image in aspect fit mode.
So an image is selected and added to the UIImageView in aspect fit mode. The problem is that this then leaves "blank space" around the image inside the UIImageView that needs trimming. I was wondering how I could then go and resize the holding UIImageView based upon the image inside.
Is this possible?
The Easy way is simply using the following code on your "imageView"
imageView.contentMode = UIViewContentModeScaleAspectFit;
Assuming you want to cut a "zoomed" section of your image to fit fully into your imageView
check your original image width and height
Assuming width is bigger in size then height , scale the image width to the holder width
center the image on your holder , the width will fit perfectly (section2) and the height will simply be cropped follow above and below the holder.
It turns out that a better approach is to use the following idea.
How to get the size of a scaled UIImage in UIImageView?
Instead of trimming the UIImageView, insert the image and then get the dimensions of the image inside the UIImageView, from there you can then resize the UIImageView to match the dimensions of the image inside.

Resizing CAShapeLayer

I have a simple test app on which my rootViewController's UIView contains a bunch of UIView subviews. Each one of those UIView subview is backed by a CAShapeLayer.
I want the composition created by those subviews ( the four shapes that are within the dotted area .. ) to always stay vertically and horizontally centered with respect to my
UIWindow. (the minimium size of the left/right, top/bottom margins will be subject to be changed at runtime at each orientation change )
So for example when i rotate to portrait i will have to
resize and reposition those single shapes so that the whole figure will be mantained centered and each CAShapeLayer sublayer stays sharp ( i want their path to be resized not just a raster resize )
what would be the best technique to resize/move the shapes to always have a centered composition while maintaining path crisp appearance for the shapes?
Ultimately for me it will be good to have an answer to this: how can i shrink the subviews as a whole? i mean their sizes and relative positions?
Thanks
You can use CGPathCreateMutableCopyByTransformingPath() or -[UIBezierPath applyTransform:] to recalculate all points in the path.

Make NSView resizable WITHOUT resizing images contained within

I have an NSView that resizes automatically based on the size of the window. I load images and display them in the NSView, but I do not want the NSView to try and "squeeze" them to fit the NSView's size. What I would like is to have the images load into the NSView at 100%, then resize the window to reveal more of the image rather than scale it to fit. I may want to modify this later to allow zooming and panning as well.
Here's what I did:
-(void)drawRect:(NSRect)rect
{
NSRect theRect = NSMakeRect((rect.size.width/2)-(([theImage pixelsWide]/2)/2),
(rect.size.height/2)-(([theImage pixelsHigh]/2)/2),
[theImage pixelsWide]/2,
[theImage pixelsHigh]/2);
[theImage drawInRect:theRect];
}
How are you displaying the images in the first place? Either you're using an NSImageView or you're drawing the images into your custom view yourself in -drawRect:.
If you're using an image view, take a look at its autosizing settings (its geometry as its parent view's geometry changes) and its image scaling properties (the image size and ratio as the image view's geometry changes.
If a custom view then draw the image into whatever rectangle you please rather than the view's entire bounds.