将图像从scrollview保存到相册

时间:2012-10-09 14:32:54

标签: iphone ios6

当我使用

时,如何将图像从scrollview保存到photalbum
 NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
滚动视图中的

以显示图像视图。

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;
}
}

在声明中以红色显示消息

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

property _image not found on object of type uiscrollview.

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以使用单独的指针挂起图像,或者如果滚动视图是指向它的唯一指针,您可以使用标记找到它:

// 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

//用标签找到它......

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