Strange behaviour with UIImageView with camera pictures, all zoomed in - ios

I have a strange behaviour which suggests I might just be missing something. I have the following code:
UIImage *anyImage = [UIImage imageWithContentsOfFile:path];
self.imageView = [[UIImageView alloc] initWithImage:newImage];
[self.imageView setImage:newImage];
self.imageView.center = self.view.center;
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.userInteractionEnabled=YES;
self.imageView.clipsToBounds=YES;
[self.view addSubview:self.imageView];
When anyImage is a smaller size picture, downloaded from the internet, it displays correctly. However, when anyImage is a picture taken from my iPhone camera, it is zoomed-in and only shows a part of the picture enlarged, covering the entire window. I have tried different approaches to resize the imageView but it has no effect. So for example, a picture of a person might have the head or part of the body all zoomed in to cover the entire window and the rest of the body not shown. How can I resolve this problem?

Related

iOS image blending like Fused app

I want to blend two UIImages as Fused App is doing:
https://itunes.apple.com/us/app/fused-double-exposure-video/id869117407?mt=8
What Fused is doing, it takes two images (foreground & background) and apply blending in such a way that background remains the same and user can move,rotate & size the foreground image. I attached two images for better understanding. I want to achieve the same behaviour in my app. I have tried all CoreImage & CoreGraphics but I could not achieve this. Help needed from all of you.
First Screen: After applying Overly blend mode.
Second Screen: Change the size of foreground image:
My Result:
You can achieve what you want by using CHTStickerView, I've used it before and it works great. CHTStickerView is a movable, resizable, rotatable UIView with one finger, which is fully customizable.
Use CHTStickerView as your foreground image and UIImageView as your background image.
So your code should look something like this:
- (void)viewDidLoad {
[super viewDidLoad];
//background
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame];
[backgroundImageView setImage:#"background.png"];
[self.view addSubview:backgroundImageView];
//foreground
UIImageView *foregroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
[foregroundImageView setImage:[UIImage imageNamed:#"foreground.png"]];
CHTStickerView *stickerView = [[CHTStickerView alloc] initWithContentView:foregroundImageView]; //set your foreground image as content in CHTStickerView
stickerView.center = self.view.center;
stickerView.delegate = self;
[stickerView setImage:[UIImage imageNamed:#"Close"] forHandler:CHTStickerViewHandlerClose];
[stickerView setImage:[UIImage imageNamed:#"Rotate"] forHandler:CHTStickerViewHandlerRotate];
[self.view addSubview:stickerView];
}
UPDATE
Alright I downloaded the app and checked out blend. I think what the app is doing is just getting the opacity value of the foreground image with the slide bar and drawing the foreground image (opacity set) on the background image.
So to set the opacity of a UIImage check this out: How to set the opacity/alpha of a UIImage?
And to draw and image over another check this out: Draw another image on a UIImage
To summarize, what you need to do is:
1) get the position and size of the CHTStickerView after user rotated and resize
2) get the UIImage from CHTStickerView, get the opacity value from slider
3) set opacity to image and draw image on your background image
Hope this helps!

Parse Background image in loginView, not fitting to fit all iPhone device screen sizes

I am trying to get my background image to fit all screen sizes within Parse's logInView. Unfortunately this code isn't doing the trick I expect it to.
[self.logInView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"Backgroundwithlogo.png"]]];
I have subclassed the PFLoginViewController to what I just called LoginViewController. I have tried resizing the image that i imported, but it either adjusts itself to be too big, or too small. The colorWithPatternImage will tile my image across the view if it's too small, and my background image seems to be stretched horizontally right now.
What I have tried:
I have tried implementing:
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Backgroundwithlogo.png"]];
[self.logInView addSubview:imgView];
[self.logInView sendSubviewToBack:imgView];
imgView.contentMode = UIViewContentModeScaleAspectFit;`
with no avail. I have read the Parse Guidelines Here. But they don't cover this issue with sizing problems inside the UI. Any help would be greatly appreciated.
UIImageView *imgView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
imgView.image = [UIImage imageNamed:#"Backgroundwithlogo.png"];
[self.logInView addSubview:imgView];
[self.logInView sendSubviewToBack:imgView];
Also, you may need a specific contentMode.

UIImage retutns wrong width

I have a UIImageView and I put it in a toolbar. When I run it on the simulator, the image gets stretched in. Meaning the width somehow gets less than the toolBar. Here's my code:
UIImageView *imageNav = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
nav.frame.size.width, nav.frame.size.height)];
nav.image = [UIImage imageNamed:[imageTop objectAtIndex:0]];
This is the output.
http://postimg.org/image/rjirnmiyx/
The yellow is the toolbar and the green thing is the image. It does not fill the toolbar.
Update
Whatever I do, it gets scaled off at the right side. (Like the image above.)
I tried all kinds of content modes and it all came down to one thing. Something does get ruined at the right hand side.
Update 2
I figured out the problem! The problem is that the UIImageView does not have a constraint. Can someone please help me add a constraint?
you can try this
[imageNav sizeToFit];
UIImage *image = [UIImage imageNamed:[imageTop objectAtIndex:0]]
UIImageView *imageNav = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
image.size.width, image.size.height)];
imageNav.image = image;
Hope above code snippet helps..

Image not resizing properly to fit the screen

Im currently stylizing my login screen of my app, but I am running into a problem that i can't solve and is very odd... The image is not resizing properly and kind of starts to repeat itself, which i find very weird because i have the correct image sizes and have them correctly named, and i am calling them in my code correctly too, so i cannot find my problem. Below is the code.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"sl_login_default"]];
colorWithPattern is meant to create a pattern out of an image. If you want to have an image in the background, create a new UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName];
backgroundImageView.frame = self.view.bounds;
[self.view addSubview:backgroundImageView];

How to add large background image on the UIView in a full size?

I have a high resolution image and I want to use it as a background for a view. But when I add it either via an Interface Builder or programatically I see only its part.This doesn't help:
UIImage* _backGround = [UIImage imageNamed:#"background-clean#2x.png"];
CGRect _viewFrame = self.view.frame;
[_backGround drawInRect:_viewFrame];
UIImageView* _backGroundView = [[UIImageView alloc] initWithImage:_backGround];
[self.view addSubview:_backGroundView];
[self.view sendSubviewToBack:_backGroundView];
And this too:
_backGroundView.contentMode =UIViewContentModeScaleAspectFit;
So the question how can I scale this image in order it fits in the view in a full size in spite of its size?
P.S. Sorry for my bad English.
I agree with Ali, when creating retina-sized images you should also scale them and add their smaller version to your project. With both versions you can simply specify the full name of the image without the #2x.png or .png extension.
But, to fix your implementation you only need one extra line of code:
UIImage* _backGround = [UIImage imageNamed:#"background-clean"];
UIImageView* _backGroundView = [[UIImageView alloc] initWithImage:_backGround];
_backGroundView.frame = self.view.frame;
[self.view addSubview:_backGroundView];
[self.view sendSubviewToBack:_backGroundView];
Once you change the frame of the UIImageView, its contents (i.e. your image) will scale as well.
You must not include #2x in your code when referencing the name of the image!
You should:
Include both files Background.png and Background#2x.png in your Xcode projet resources, Background#2x.png being twice the size (in pixels) of Background.png
But always refer to this file (for example in imageNamed:) as #"Background.png" or even just #"Background": [UIImage imageNamed:#"Background"]
Then iOS will do its magic all by itself, choosing the right image between Background.png or Background#2x.png depending on if the device screen is Retina or not.
For more info see here in Apple documentation.
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background-clean"]]];

Resources