UIGetScreenImage() crops on iPhone 4 - uiview

UIGetScreenImage() works fine on my app on iPhone 3 (3G, GS) but on iPhone 4 it seems to get only a cropped area (upper left). I use UIGetScreenImage() to capture a frame from the camera.
Here is some code
CGImageRef iref = UIGetScreenImage();
UIImage *tmpImage = [[UIImage alloc] initWithCGImage:iref];
And afterwards I save it to photo album successfully. Any ideas?

its because of the double resolution of the retina screen, you are getting a quarter of the screen I imagine.
Read this, explains exactly what you have to do :)
http://developer.apple.com/library/ios/#qa/qa1703/_index.html

Related

Aspect Ratio of Background Image for iPhone X

I have an app which has image asset with 3 size images #1, #2, #3 as a background image.
I implement launch screen into my project to make app seen as fullscreen on iPhone X. As you know, launch screen asset has size for iPhone X so launch screen looks okay.
However, my background image doesn't look good because #3s' aspect ratio is for plus devices not iPhone X.
Where should I add a proper size image?
EDIT: My question is not about launch screen Image. It is about an background image that I use on regular ViewController
Rather than use an image as your launch screen, you should try using a launch storyboard.
This could contain a single view controller that contains a UIImageView, with contentMode = .aspectFill. This will clip some of the image on either side, but this might be acceptable to you.
It is not a best approach but I solve it by creating another image asset and put iPhone X background image to its #3 area. Then In code I check If It is iPhone X screen, If yes I use image asset with x background, If other use default image asset.
- (void) setBackgroundImage{
// Load launch image
NSString *launchImageName;
if ([UIScreen mainScreen].bounds.size.height == 812){
launchImageName = #"PublicBackground_X"; // iPhone X
}
else {
launchImageName = #"PublicBackground"; // Other iPhones
}
UIImage *image = [UIImage imageNamed:launchImageName];
[self.backgroundImage setImage: image];
}
EDIT:
I don't know why I get bad reputation. None of other solutions worked for me. Clipping an Image shouldn't be acceptable If u have right resolution

What size has a background image to have?

I'm developing a game in Swift (but not sprite kit), and i'm having a lot of trouble to make a background image that look great in every device. I recently understand the concept of the #1x, #2x and #3x images and it's pixels, but i can't find any place that say what size (width and height) an background image must have to look good both in canvas mode, preview mode and in action.
Anyone can help me?
For help, i'm attaching two print screens of a test that i made.
Thanks for the help :)
Image on Xcode 7 canvas
image in preview mode. Notice how he cut the edges
Size Icon For Devices:
UIImageView *imageView = [UIImageView alloc]init];
imageView.frame = CGRectMake(0,0,widthInt,heightInt);
imageView.image = [UIImage ImageWithName:#"nameImage.png"];

UIImagePickerController Image returned is bigger than preview on iPhone 4

I'm taking a photo with UIImagePickerController. Everything works fine on iPad and on iPhone 5. The problem comes with an iPhone4: the photo that I get from the picker is "bigger" than what I saw on the screen when I took the photo.
What do I mean with bigger? I mean that at both sides of the photo, and at the bottom, I see parts of the scene that the camera didn't show when I was taking the photo. This is a problem for my app. I need to capture exactly the same scene that the user sees through the camera when he takes the photo. Not a bigger scene. As I said, on iPhone5 and iPad4 everything works fine. I don't understand this different behaviour. How can I solve this?
PD: I'm not applying any transformation to the image on the picker.
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
UIImage* originalImage = [info valueForKey:#"UIImagePickerControllerOriginalImage"];
NSLog(#"Image Size Width %f Height %f",originalImage.size.width,originalImage.size.height);
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
[originalImage drawInRect:CGRectMake(0,0,320,480)];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(#"image Size h %f Width %f",[image size].height, [image size].width);
}
Here you can see that What is original image size and after than you can change size as your wish..
It was a problem with the preview on the iPhone4... the preview on the iPhone4 is 16:9, but the final image is 4:3. On the iPhone5 and the iPad, both the preview and the final image are 4:3.
I didn't realize it before because my overlay was hiding part of the preview on the iPhone4, so I thought the preview was 4:3 too (and I think that the preview with iOS6 is 4:3, I'm not sure, I've got to find an iPhone4 with iOS6).
I made my overlay (a UIToolbar) translucent, and now I get what I want.

iOS image sizes for iPad and iPhone

I have developed an small iOS app, where i have image named bg.png which is of dimension
1024 * 768 for iPad.
Now i have many images which has been created for iPad size. Now i need to make support of this app in iPhone, for that weather i need to create same set of images agian for iPhone size,
568 * 300 for iPhone.
or there is another way to do this?
Scaling down the iPad image assets will destroy UX on iPhone. Also images like icon, splash screen usually contain company logo. Scaling down will tamper the look of the logo and overall image. Better way is to create separate images for iPhone form factor. Trim the png files using http://tinypng.org/ to keep binary size low.
Cheers!Amar.
You can use this code to re-size the image by following code,
CGSize newSize = CGSizeMake(568, 300);
UIGraphicsBeginImageContext(newSize);
[yourIpadImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
newIphoneImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
You have option to change the Size of Your Image
sathiamoorthys solution is a difficult way or rescaling your image. You can do that by simply creating a UIImageView, initialize it with a UIImage and then change its frame.
Note that your image will look scaled/distorted that way.
follow this:
open the image in preview.
go to tools > adjust size
put in whatever size you want.
save the image as a different name.
yes
you should create duplicate and resize them for iphone. Using same images for iphone will bring memory issues because the images are unnecessarily big for iphone.
Use any software to resize them or you can do this using preview also as Nikita described above
If you are doing this to create universal app then you must postfix ~ipad in the name of the image file.
Please visit this link, May help you and solve your issue.
There is the some tips like:
Propotional scale,
Resize
If you want your images to show up unscaled, you are going to need an additional image with the correct size.
So supporting both iPad with and without retina screens would require one image of 768x1024 and one of 1536 x 2048. For iPhone 3.5" you would need 960 x 640 when it is a retina screen or 480 x 320 when it is non-retina. For iPhone 5 (4" screen) you would need 568 x 320.
If you use UIImages method imageNamed: there is help from Apple. It loads on retina devices that method looks for the the image you specified with the postfix '#2x'. So you can simply code:
UIImage * myImage = [UIImage imageNamed: #"myImage"]
If you make sure you project contains myImage.png for non-retina devices and myImage#2x.png for retina devices the right image gets loaded at runtime.

Cropping UIImage from photo library vs iPhone camera

I can crop images from the iPhone's photo library no problem like this:
CGRect topRect = CGRectMake(0, 0, image.size.width, image.size.height / 2);
CGImageRef topCroppedCGImageRef = CGImageCreateWithImageInRect(image.CGImage,
topRect);
UIImage *croppedImage = [[UIImage alloc] initWithCGImage:topCroppedCGImageRef];
CGImageRelease(topCroppedCGImageRef);
However this doesn't work when the image comes from the camera. Specifically the cropped image is rotated and the cropped portion isn't as expected. After reading around it sounds like this problem is relatively common. However I've tried the various code fixes and it's not quite working (still have rotation, unexpected cropping and even distortion issues). So I'd like to actually understand why the above cropping doesn't just work for images coming from the camera.
Why doesn't the above cropping method work on images coming from the iPhone's camera?
As pointed out by this famous post - Resize a UIImage the right way, this is because you leave out functionality such as EXIF orientation support, an absolute necessity when dealing with photographs taken by the iPhone’s camera.
By default (picture taken in portrait) the image has an EXIF orientation flag = 6 which means the image is rotated 90 degrees counterclockwise:
$ identify -format "%[EXIF:orientation]" myimage.jpg
6

Resources