user1452248
user1452248

Reputation: 767

Save image from scrollview to photo album

How to save image from scrollview to photalbum when i m using

 NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

in scrollview to display image view.

UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
   imageScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 61;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;
NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);


-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
    case 0:
        UIImageWriteToSavedPhotosAlbum(_imageScrollView._image, self, nil, nil);

        break;

    default:
        break;
}
}

Getting message in red on statement

   UIImageWriteToSavedPhotosAlbum(_imageScrollView._image, self, nil, nil);

that property _image not found on object of type uiscrollview.

Thanks for help.

Upvotes: 0

Views: 220

Answers (1)

danh
danh

Reputation: 62676

You can hang on to the image with a separate pointer, or if the scroll view is the only pointer to it, you can find it with a tag:

// right after
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// give it a tag
imageView.tag = 128;   // any int that is unique relative to other tags in the scroll view

// find it with the tag...

case 0:
    UIImageView *imageView = (UIImageView *)[imageScrollView viewWithTag:128];
    UIImageWriteToSavedPhotosAlbum(imageView.image, self, nil, nil);

    // notice, there's also no property called _image on an imageView

Upvotes: 1

Related Questions