Rendering a full sized image with UIGraphicsImageRenderer - ios

Images taken with our device camera's are larger than the screen on our iOS device.
Usually when we render an image in iOS i see people setting their rendering size to the size of the main view or their image view.
As shown in this stack overflow response.
Doing so will make the image smaller and lower quality.
If the logic follows.
Would it be possible to render the image with it's full size if I make the image view go beyond the device screen. In other words the image view will be set to the size of the original full sized image.
Will doing this generate a rendered image with the same pixel size of the original image ?
What have I done so far ?
I have tested other image overlaying/editing apps and they seem to reduce the image's pixel size.
I used the methods provided in the link above and they also do the same.

Yes it's definitely possible by embedding a UIImageView in a UIScrollView and using sizeToFit:
imageView.image = image;
[imageView sizeToFit];
scrollView.contentSize = image.size;
You will then be able to pan across the image within the scroll view.

Related

Swift: is possible to get the default size of UIImageView used by UIImagePickerController?

In my iOS app I am developing, it is necessary for the user to take a photo. As you can see from the following image
by default, when we take a photo with iOS camera app, then it is showed with a standard/default size (the one delimited by those 8 pins) and I would like my app to be the same. So, which size should I set my UIImageView into which the photo will be displayed? How can I get that default size in Swift?
Or maybe...which would be the best size to give to UIImageview to prevent the photo from being deformed too much?
Thank you very much for you attention
UIImage has a property called size which specifies width and height of the image. So you could size your UIImageView to those.
Alternatively, if you're using constraints or autoresize mask (flexible width, flexible height) simply don't set a size and the UIImageView will fill itself according to contentMode.
You must understand however that what you see in the image you posted is not the "original size" of the image. Someone decided that the UIImageView should be place at X distance from top and bottom margins, thus forcing an implicit size on the UIImageView

Maintain image quality in iOS Application

I am trying to create a photo application but I am having a tough time formatting my photos so that they show clearly.
I have an imageview size 320 * 500, and an image size 3648*2736 px (Which of course I can scale down).
imageView.contentMode=UIViewContentModeScaleAspectFit;
With imageView.contentMode=UIViewContentModeScaleAspectFit; I changed the image size to 700* 525px (IMGA) and one 500 * 325(IMGB).
In this mode
IMGA fills the entire image view but is somehow a little distorted/not crisp
IMGB does not fill the entire image view Top and Bottom but the width is perfect and the image is crisp.
UIViewContentModeScaleAspectFill
With UIViewContentModeScaleAspectFill
the image is made for fit into the uiimageview but again distorted even if the image is scaled down vs being scaled up.
I see many apps with crisp large images . and I am hoping that someone helps me with measuring/ contentmode to get my images better.
Or correct my resizing
P.S I have been looking at this link to try help but I'm still missing my goal.
Difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill?

how to resize image without affecting its resolution in ios

I have an image view in which I have set image.It works fine if the size of image and image view is almost same. But what if we change the device, Image view is inc in size but the image gets stretched. I am unable to find any way to resize this image such that the image is not affected by the size of image view and at the same time remain centralized also. Also resolution of the image should not be affected.
you can use
[imageView setContentMode:UIViewContentModeScaleAspectFill];
or
[imageView setContentMode:UIViewContentModeScaleAspectFit];
Aspect Fit: Will size your image until the whole image will fit within your UIImageView Box. Thats why you are left with the extra space on top and bottom.
Aspect Fill: Will size your image proportionally until the whole UIImageView is full of your image. So that is why you see clipping of your image. It will actually size it proportionally to make sure there is no blank space left in your imageview.
In a nutshell: Aspect Fit makes sure your whole image is visible proportionally. Aspect Fill will make sure there is no space left in the imageview while sizing your image proportionally.
so it is upon you what you can compromise.
a rendom google image for example.
use this imageViewName.contentMode = UIViewContentModeScaleAspectFit;
as per docs This option is used to scale the content to fit the size of the view by maintaining the aspect ratio

Can't get UIImageView to resize to fit screen

I've got an image which I want to display in a UIImageView and want it to automatically resize to fit the view, and fit the screen size of the device (iPhone 4, 6, and 6+ sizes).
However I've set the view mode of the UIImageView and its parent UIView to be AspectFit but the image doesn't scale to fit the view. Why does the image not shrink to fit within the UIImageView even though the view mode is set to AspectFit?
(I"m using Xcode 6)
Both aspect fill and aspect fit are used to size the image view to the size of the photo inside of it.
Aspect fit sizes your image so that the whole thing fits within the bounds of your image view.
Aspect fill sizes your image so that it fills up the whole image view (which can result in clipping).
More info on those definitions here.
What you most likely want to do is manually size your image view to fit the screen. The easiest way to do this might be to use something like the following, that way it will size to whatever device you're using.
[self.myImageView setFrame:self.view.bounds];

I have few images and I want to show it on iPad on the full screen?

I have few images and I want to show it on iPad on the full screen - with same images. and image sizes are not same. Is there way to Stretch images (UIImageView) programmatically
Thank you
To stretch an image within UIImageView you just need to set the appropriate contentMode.
You can set the UIImageView to be the size of the screen and set the content mode like follows
3 options
// assume iv is an UIImageView the size of screen
// First option stretches your image to the size of the screen
[iv setContentMode:UIViewContentModeScaleToFill];
// Second option scales your image without changing aspect ratio to the largest possible size such that the whole image fits
[iv setContentMode:UIViewContentModeScaleAspectFit];
// Third option scales your image without changing aspect ratio to the smallest possible size such that the screen is covered (potentially clipping some of your image)
[iv setContentMode:UIViewContentModeScaleAspectFill];

Resources