Как сохранить составное или измененное изображение для iOS Development? - PullRequest
0 голосов
/ 27 июня 2011

Я добавил оверлей к своему изображению (выбранный из фотоальбома) и не могу сохранить композицию, следующий код сохраняет только исходное изображение. У кого-нибудь есть предложение изменить объект изображения, чтобы добавить изображение?

    #pragma mark -
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
    overlay.alpha = 0.6;  // Customize the opacity of the top image.
    [imageView addSubview:overlay];
    CGContextRef context = UIGraphicsGetCurrentContext();
    //UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
        // Save image
    UIImageWriteToSavedPhotosAlbum(imageView.image, self,                                    @selector(image:didFinishSavingWithError:contextInfo:), context);
    [picker dismissModalViewControllerAnimated:YES];
}

Ответы [ 2 ]

1 голос
/ 27 июня 2011

UIImageWriteToSavedPhotosAlbum (imageView.image.layer, self)

0 голосов
/ 30 июня 2011

Спасибо @Рахул Вьяс. Я не попробовал ваше предложение, но я все еще ценю ваш вклад. Закончилось решением этой проблемы с помощью форумов Apple Dev.

Ответ на эту проблему таков: у меня все получилось:

CGRect screenRect = [[UIScreen mainScreen] bounds];    
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef context = UIGraphicsGetCurrentContext(); 
[[UIColor blackColor] set]; 
CGContextFillRect(context, screenRect);
[imageView.layer renderInContext:context];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), context);
[picker dismissModalViewControllerAnimated:YES];
...