检索TTPhotoViewController的UIImage

时间:2010-08-05 10:34:51

标签: iphone objective-c three20

我有一个TTPhotoViewController子类很好地工作。我需要能够选择将下载的图像保存到用户保存的照片目录中。我在检索UIImage对象时遇到了问题。

查看API后,我看到TTPhoto(视图控制器的属性之一)实际上并不包含要使用的UIImage。但是,在API中有一个TTImageView类,它具有UIImage属性。 TTPhotoView派生自TTImageView,我的视图控制器类中有一个名为“PhotoStatusView”。但是当我访问它时,我没有得到UIImage。

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

查看此网站add save to album functionality

以下是该网站的代码:

    _clickActionItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                        UIBarButtonSystemItemAction
                        //TTIMAGE(@"UIBarButtonReply.png")
     target:self action:@selector(clickActionItem)];



  UIBarButtonItem* playButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
    UIBarButtonSystemItemPlay target:self action:@selector(playAction)] autorelease];
  playButton.tag = 1;


  UIBarItem* space = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
   UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
  _toolbar = [[UIToolbar alloc] initWithFrame:
    CGRectMake(0, screenFrame.size.height - TT_ROW_HEIGHT,
               screenFrame.size.width, TT_ROW_HEIGHT)];
  _toolbar.barStyle = self.navigationBarStyle;
  _toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth
                              | UIViewAutoresizingFlexibleTopMargin;

    NSString *searchCaption = @"Photo from networked";
    NSRange range = [[_centerPhoto caption] rangeOfString:searchCaption];

    if (range.location == NSNotFound) {
        _toolbar.items = [NSArray arrayWithObjects:
    space, _previousButton, space, _nextButton, space,_clickActionItem, nil];
  [_innerView addSubview:_toolbar];
    }else{
        _toolbar.items = [NSArray arrayWithObjects:
                          space, _previousButton, space, _nextButton, space, nil, nil];
        [_innerView addSubview:_toolbar];

    }

和这个

   - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{

    if(6 == actionSheet.tag)
    {
        if(0 == buttonIndex)//save page

        {           

            NSLog(@"photo: %@", [_centerPhoto URLForVersion:TTPhotoVersionLarge]);


            NSURL    *aUrl  = [NSURL URLWithString:[_centerPhoto URLForVersion:TTPhotoVersionLarge]];
            NSData   *data = [NSData dataWithContentsOfURL:aUrl];
            UIImage  *img  = [[UIImage alloc] initWithData:data];

            NSLog(@"photo:class %@", [img class]);

            UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);

答案 1 :(得分:0)

你应该尝试使用:

UIImage *image = [[TTURLCache sharedCache] imageForURL:URL];