Change the resolution of image in iPhone? - iphone

I wanted to change the resolution of a image,this image I am getting from remote location.The image I am getting is too large to fit in iPhone screen is their any way to change that resolution?

If you're using a UIImageView then UIView's contentMode is what you need, you should probably set it to UIViewContentModeScaleAspectFit (or the equivalent in Interface Builder).

Assuming you are using some kind of "View" to display the image (rather than custom drawing) you might see if there is some kind of property which would allow you to set the "Mode" of the view to allow various scaling methods.

If you render it, it should scale anyway (see UIImage::drawInRect) However, CGContextDrawImage will scale draw an image into a new context, which you can then use to render to the screen.

If you're looking to actually resize a UIImage to smaller dimensions, this blog post might help.

Related

Swift how to show only part of image?

I have got an image 300px300px, but i only want to show 100x100 of it, just like here https://www.pinterest.com/pin/31103053652400980/ background photo is only showing part of it.How can i do that?
You can use UIImageView that has property Clip To Bounds on. After that you can change Content Mode of the `UIImageView' that suits you.
Example:

Image aspect ratio swift ios

So, I'm learning iOS Swift. I'm going by some tutorials, and I'm stucked at image positioning.
I'm trying to figure out how uploaded picture is rescaled and positioned.Since I cannot post the screenshot, image that should be shown in my simulator as whole, I can only see like 25% of the picture. Should I change something in Attributes or in Size Inspector?
What I did so far (clearly wrong), was setting Intrinsic Size field -> select Placeholder, w/h = 320.
Then, I pinned and selected Aspect Ratio.
Any help, please?
Thanks.
If you're asking how to make sure an image fills a UIImageView:
myImageView.contentMode = UIViewContentMode.ScaleAspectFill
You may also need to set constraints if you placed your image view in interface builder.
It's not entirely clear from your question how you want it positioned, but hopefully these get you on the right path.

Zoom out on large UIImageView within an UIScrollView

Case: I have a simple piece of code for displaying/zooming/scrolling a large image in an UIImageView->UIScrollView. In this UIScrollView content I want to place buttons to create clickable areas.
Issue: When I zoom in the quality remains proper but, when I zoom out to the highest posible level than the image is getting dotted and some lines aren't visible anymore.
Tried: I tried to regenerate the UIImage with Interpolation Quality on kCGInterpolationHigh and tried to change the size of the image after every zoom change. As you might aspect, no results jet.
I suggest you use a CATiledLayer as the backing layer, as demonstrated by Apple's PhotoScroller sample app. This allows you to prebuild the scaled versions, meaning you can precisely control the interpolation quality with Photoshop/ImageMagick/GIMP etc, rather than relying on UIScrollView's built-in scaling.

Image "frame/window" on iphone

I have numerous photos in portrait and landscape format. I want to be able to display a "crop" of the photo in a UIImageView on the iphone. If the picture is in landscape format I want it to resize to fit the frame, if it is in portrait format I need it to resize to fit the width, and then be cropped at the top and bottom. As if there is a "window" over the image - so it looks like a landscape picture.
It would be even better if this could be a UIButton - although I am aware that I can use touchesBegan and such on images to make it behave like a button if needs be.
Thanks for any help you can give me.
Thanks
Tom
In an ImageView, you can change the View Mode to Aspect Fill. It will give you the right scaling/cropping you want.
For interactions, you can use a Custom button with no drawing at all (no Title, no Image, no Background) with the same size as your ImageView. That would be safe with regards to the image aspect. I've tried similar stuff using the button's Background or Image properties, it can have some undesired effects (I've ran into a resizing issue on iOS 3.1.3 for instance).
1°) To Crop the Image, try to add a method to UIImage class to do it (you can google it without problem, or even on StackOverFlow)
2°) To add a "window" over your image, just add an UIImageView over your image wich has transparency. It should work ;-)
3°) To know when an image is touched, you can use "touchesBegan" to detect which image were selected. But I think it's the last of your problems ^^
What you cant to achieve isn't so hard, just to it step by step !
If you want more help in one step, say it. But I can't code it all for you ;-)
Good Luck

UIImageView scaling/interpolation

I have a small IPhone app that I am working on and I am displaying an image with a UIImageView. I am scaling it up using the Aspect Fit mode. I would like to have the image scale up with no interpolation/smoothing (I want it to look pixellated). Is there any way I can change this behavior?
A little more general question would be can I implement my own scaling algorithm, or are there other built in ones that I can select?
You would need to set the magnificationFilter property on the view's layer to the nearest neighbour filter:
[[view layer] setMagnificationFilter:kCAFilterNearest]
Make sure you include the line
#import <QuartzCore/CALayer.h>
At the top of the file containing the call to setMagnificationFilter or it won't compile.
Swift
imageView.layer.magnificationFilter = kCAFilterNearest
imageView.layer.shouldRasterize = true
There are two ways you could do this. You can either implement a rescaling algrorithm without interpolation. If this is to much work you could rescale the image in another application like gimp or photoshop. This would work unless you needed to change the size dynamically in your application.