Reputation: 987
In my application while user try to upload image, I want image size based on the screen resolution.
For example If image size is 9690 X 4400 then it should return its size depend on screen resolution instead of actual size.
For mac application (OSX) we can do with this statement and its return me size 561 X 264
NSImage *imageUpload = [[NSImage alloc] initWithContentsOfFile:fileName];
Same like mac how can we do for iOS app, any idea? plz help.
Is there any way to get this? I did google but not finding any results.
Thanks
Upvotes: 0
Views: 705
Reputation: 1165
Try something like this:
First you should to calculate aspect ratio of your view:
double viewAspectRatio = myView.bounds.size.width / myView.bounds.size.height;
Second you should to calc aspect ratio of your image:
double imageAspectRatio = myImage.size.width / myImage.size.height;
So finally
CGSize scaledSize;
if (imageAspectRatio > viewAspectRatio) {
scaledSize = CGSizeMake(myView.bounds.size.width, myView.bounds.size.width / imageAspectRatio);
} else {
scaledSize = CGSizeMake(myView.bounds.size.height * imageAspectRatio, myView.bounds.size.height);
}
Upvotes: 1