アプリで画像の「保存」ボタンを探しています。問題は、iPhone 5 と iPhone 4 の画像がぼやけていることです。これは私が現在使用している私のコードです。
iPhone 4 および 4s ユーザーの場合:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[self.view.layer renderInContext:ctx];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake (0, 20, self.view.bounds.size.width, (self.view.bounds.size.height - 40)));
//save photo to photoAlbum
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Saved!"
message:@"Image has been Saved, don't forget to Share!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Request to save the image to camera roll
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil); }
iPhone 5 ユーザーの場合:
if(result.height == 568)
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[self.view.layer renderInContext:ctx];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake (0, 40, self.view.bounds.size.width, (self.view.bounds.size.height - 150)));
//save photo to photoAlbum
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Saved!"
message:@"Image has been Saved, don't forget to Share!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Request to save the image to camera roll
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil); }
}