In my app I use a custom camera and when I snap a photo I want to see it in an UIImageView, it's all ok it work, but there is a little problem: when it put the UIImage (from camera) in UIImageView, the image sems a little flattened, then what's the exactly resolution that I should to set for UIImageView to have an exactly copy of my original UIImage?
ok, I set aspect fill in IB and it's all ok
The images resolution depends on the device that you are using. For the iPhone 4, it's 2592x1936.
I think it's more likely that you might be looking for the aspect ratio for the image, which is always 4:3. Keep in mind however, that a) you don't know whether the image will be portrait or landscape and b) that, if you allow to take an image from a photo album, you don't have control over the resolution/ratio at all.
So the most prudent thing to do might be to just set the UIImages fill mode to 'Aspect Fill' or 'Aspect Fit'.
Related
I have a very simple requirement here but I'm looking for a solution for a while. I want to take a profile picture form the camera roll or camera and display it in two different image views (different sizes). I don't want any of these images stretched or miss any part of the image. If I use aspect to fit, top side of image is cut from smaller image view and some parts missing on the bigger image view. If I set it as scale to fit, it will get stretched!
I'm not sure how some mobile apps work. Do they save different image sizes in their server or they change the size of the image. I saw many posts how to change image size without changing aspect ratio. But I don't think it is possible to avoid stretched effects. I used some of those code to change size of image, it gets stretched all the time.
Is there any way to save the image from camera roll one time with size of 140*200 and one time 160*200? So I can use 140*200 for image views that size. But what if I have different devices and different sizes.
On some view controllers I am using images as background for the whole screen. I was wondering what is the best practice for this, since I want to support all currently available iPhones (5-7). Normally for images I would get #2x and #3x image, but here the case is a little bit different?
Do I add 4 photos to app and then ask system on which device i am running and than load appropriate photo? This seems kinda clunky, an not really elegant.
You don't really have that many options.
You could bundle different images for the different device aspect ratios, check the device aspect ratio at runtime, and load the correct image. This implementation is flawed, as it doesn't account for future device aspect ratios. You could have a webservice which returns a correct image for a given aspect ratio, to take that work off of the client.
You could also create a single image that looks good on all device sizes, and load the image into a UIImageView and set its contentMode UIViewContentMode.scaleAspectFill to fill the entire image into the view's frame, cropping some portion of the top, bottom, or sides out.
I've solved this in my projects by using the 'xcassets'. The system basically takes care of the 'which device size' question for you. Also, play around with the differing contentMode properties (i.e.'aspectFit', 'aspectFill', 'scaleToFill').
Another thing I would watch out for is the value for 'autoResizingMask' property. In most cases if my sizing isn't doing what I think it should, I check if I gave autoResizingMask a value of 'No'.
I hope this helps!
I'm making my first iphone game using swift/xcode with gimp to draw the graphics. I'm having trouble understanding what size I should make the image in gimp to use it for the background of my iphone game.
The various devices have different screen sizes, so presumably you will want your image to adapt. Thus it really isn't about your image but about the image view that will display it (assuming you're using an image view). The things to think about are:
How to use constraints to pin the edges of the UIImageView to the edges of the screen.
How to set the content mode of the UIImageView so that it displays the image acceptably on all device sizes.
I have a valid image with the right content size, however I have noticed when I try to paste this image to WhatsApp or through iMessage the image get's significantly stretched. I have looked at the image and it seams to be fine on UIImageview, but somehow it gets stretched in particular to outer controls.
Is there anyway to fix this issue?
When copying an image make sure to modify the imageView's mode. There are different modes, like Aspect Fit, Scale to fill and so on.
If let's say the image is 500x300 and your imageView's size is set to 350x230 and mode to Scale to fill, it will end up stretched. Try to fiddle around and see what works for you. Most of the times i choose Aspect Fit.
Try that out.
BTW. You can find it under inspection tab in design editor or set it programmatically if you choose so.
I'm using UIImagePickerController to fetch images from the user's photo library and/or taken with the camera. Works great.
I'm noticing that fetched images are often (always?) coming back with their imageOrientation set to UIImageOrientationRight. But the image was captured with the device in portrait orientation. Why is this? This is an iPhone4S, iOS6, using the rear camera - so the resolution is 8MP.
In the simulator, grabbing photos from the photo library, images come back UIImageOrientationUp.
When I display the image in a UIImageView the orientation looks correct (portrait/up). But when I go to crop the image the coordinate system isn't what I would expect. 0,0 is in the upper-right of the image, which I guess makes sense when it reports UIImageOrientationRight.
I'm looking for an explanation of what's going on and the correct approach to dealing with the odd coordinate system.
EDIT: it sure appears to me that, on iPhone4S at least, the camera always takes UIImageOrientationRight/"landscape" images, and that UIImageView is respecting the imageOrientation on display. However, if I save the image using UIImagePNGRepresentation the orientation is not preserved (I think I read about this somewhere.)
It has to do with the orientation the phone was in when the image was taken. The phone doesn't rotate the image data from the camera sensor to make up in the image be up but instead sets the imageOrientation and then UIImage will take care of rendering things the right way.
When you try and crop, you typically change the image to be a CGImage and that loses the orientation information so suddenly you get the image with a strange orientation.
There are several categories on UIImage that you can get that will perform image cropping while taking imageOrientation into account.
Have a look at link or link