简体   繁体   English

检索TTPhotoViewController的UIImage

[英]Retrieving the UIImage of a TTPhotoViewController

I have a TTPhotoViewController subclass working nicely. 我有一个TTPhotoViewController子类很好地工作。 I need to be able to give the option of saving the image downloaded to the user's saved photos directory. 我需要能够选择将下载的图像保存到用户保存的照片目录中。 I am having problems actually retrieving a UIImage object. 我在检索UIImage对象时遇到问题。

After looking through the API I have seen that TTPhoto (which is one of the properties of the view controller) doesn't actually contain a UIImage to use. 在浏览API之后,我看到TTPhoto (它是视图控制器的一个属性)实际上并不包含要使用的UIImage。 However, within the API there is a TTImageView class which has a UIImage property. 但是,在API中有一个TTImageView类,它具有UIImage属性。 TTPhotoView derives from TTImageView and there is one of these in my view controller class called "PhotoStatusView". TTPhotoView派生自TTImageView ,我的视图控制器类中有一个名为“PhotoStatusView”。 However when I access this I do not get a UIImage back. 但是当我访问它时,我没有得到UIImage。

Any ideas? 有任何想法吗?

Check this site out add save to album functionality 检查此网站, 添加保存到相册功能

Here is the code from the site: 以下是该网站的代码:

    _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];

    }

and this 和这个

   - (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);

你应该尝试使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM