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
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.