开发者

Three20 to save images?(Close)

开发者 https://www.devze.com 2023-03-01 06:10 出处:网络
i\'m a new iPhone application developer,i need create one application like photo gallery.Now my problem is i donno how to save a image to photo album.

i'm a new iPhone application developer,i need create one application like photo gallery.Now my problem is i donno how to save a image to photo album.

i have build my project is no error no werning to me.in my simulator can run the project.

But i cnt see any things i add.Hope can help me.Thanks.

my code here.

Three20PhotoDemoAppDelegate.h

#import <UIKit/UIKit.h>

@interface Three20PhotoDemoAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

Three20PhotoDemoAppDelegate.m

#import "Three20PhotoDemoAppDelegate.h"  
#import "AlbumController.h"  
#import <Three20/Three20.h>  

@implementation Three20PhotoDemoAppDelegate  

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {      
    
    // Override point for customization after application launch  
    TTNavigator* navigator = [TTNavigator navigator];  
    TTURLMap* map = navigator.URLMap;  
    [map from:@"demo://album" toViewController:  [AlbumController class]];  
    
    [navigator openURLAction:[TTURLAction actionWithURLPath:@"demo://album"]];  
    return YES;  
}  
 
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)URL {  
    [[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:URL.absoluteString]];  
    return YES;  
}  

- (void)dealloc {  
    [super dealloc];  
}  
@end

PhotoSource.h

#import <Three20/Three20.h>  
#import <Three20/Three20+Additions.h>  
typedef enum {  
    PhotoSourceNormal = 0,  
    PhotoSourceDelayed = 1,  
    PhotoSourceVariableCount = 2,  
    PhotoSourceLoadError = 4,  
} PhotoSourceType;  

@interface PhotoSource : TTURLRequestModel <TTPhotoSource> {  
    PhotoSourceType _type;  
    NSString* _title;  
    NSMutableArray* _photos;  
    NSArray* _tempPhotos;  
    NSTimer* _fakeLoadTimer;  
}  

- (id)initWithType:(PhotoSourceType)type title:(NSString*)title  
            photos:(NSArray*)photos photos2:(NSArray*)photos2;  

@end 

PhotoSource.m

import "PhotoSource.h"

@implementation PhotoSource  
@synthesize title = _title;  

- (void)fakeLoadReady {  
    _fakeLoadTimer = nil;  
    
    if (_type & PhotoSourceLoadError) {  
        [_delegates makeObjectsPerformSelector: @selector(model:didFailLoadWithError:)  
                                    withObject: self  
                                    withObject: nil];  
    } else {  
        NSMutableArray* newPhotos = [NSMutableArray array];  
        
        for (int i = 0; i < _photos.count; ++i) {  
            id<TTPhoto> photo = [_photos objectAtIndex:i];  
            if ((NSNull*)photo != [NSNull null]) {  
                [newPhotos addObject:photo];  
            }  
        }  
        
        [newPhotos addObjectsFromArray:_tempPhotos];  
        TT_RELEASE_SAFELY(_tempPhotos);  
        
        [_photos release];  
        _photos = [newPhotos retain];  
        
        for (int i = 0; i < _photos.count; ++i) {  
            id<TTPhoto> photo = [_photos objectAtIndex:i];  
            if ((NSNull*)photo != [NSNull null]) {  
                photo.photoSource = self;  
                photo.index = i;  
            }  
        }  
        
        [_delegates makeObjectsPerformSelector:@selector(modelDidFinishLoad:) withObject:self];  
    }  
}  

- (id)initWithType:(PhotoSourceType)type title:(NSString*)title photos:(NSArray*)photos  
           photos2:(NSArray*)photos2 {  
    if (self = [super init]) {  
        _type = type;  
        _title = [title copy];  
        _photos = photos2 ? [photos mutableCopy] : [[NSMutableArray alloc] init];  
        _tempPhotos = photos2 ? [photos2 retain] : [photos retain];  
        _fakeLoadTimer = nil;  
        
        for (int i = 0; i < _photos.count; ++i) {  
            id<TTPhoto> photo = [_photos objectAtIndex:i];  
            if ((NSNull*)photo != [NSNull null]) {  
                photo.photoSource = self;  
                photo.index = i;  
            }  
        }  
        
        if (!(_type & PhotoSourceDelayed || photos2)) {  
            [self performSelector:@selector(fakeLoadReady)];  
        }  
    }  
    return self;  
}  

- (id)init {  
    return [self initWithType:PhotoSourceNormal title:nil photos:nil photos2:nil];  
}  

- (void)dealloc {  
    [_fakeLoadTimer invalidate];  
    TT_RELEASE_SAFELY(_photos);  
    TT_RELEASE_SAFELY(_tempPhotos);  
    TT_RELEASE_SAFELY(_title);  
    [super dealloc];  

    
    
    
}  





- (BOOL)isLoading {  
    return !!_fakeLoadTimer;  
}  

- (BOOL)isLoaded {  
    return !!_photos;  
}  

- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {  
    if (cachePolicy & TTURLRequestCachePolicyNetwork) {  
        [_delegates makeObjectsPerformSelector:@selector(modelDidStartLoad:) withObject:self];  
        
        TT_RELEASE_SAFELY(_photos);  
        _fakeLoadTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self  
                                                        selector:@selector(fakeLoadReady) userInfo:nil repeats:NO];  
    }  
}  

- (void)cancel {  
    [_fakeLoadTimer invalidate];  
    _fakeLoadTimer = nil;  
}  

- (NSInteger)numberOfPhotos {  
    if (_tempPhotos) {  
        return _photos.count + (_type & PhotoSourceVariableCount ? 0 : _tempPhotos.count);  
    } else {  
        return _photos.count;  
    }  
}  

- (NSInteger)maxPhotoIndex {  
    return _photos.count-1;  
}  

- (id<TTPhoto>)photoAtIndex:(NSInteger)photoIndex {  
    if (photoIndex < _photos.count) {  
        id photo = [_photos objectAtIndex:photoIndex];  
        if (photo == [NSNull null]) {  
            return开发者_如何学JAVA nil;  
        } else {  
            return photo;  
        }  
    } else {  
        return nil;  
    }  
}  
 

@end

Photo.h

#import <Three20/Three20.h>  

@interface Photo : NSObject <TTPhoto> {  
    id<TTPhotoSource> _photoSource;  
    NSString* _thumbURL;  
    NSString* _smallURL;  
    NSString* _URL;  
    CGSize _size;  
    NSInteger _index;  
    NSString* _caption;  
}  

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size;  

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size  
          caption:(NSString*)caption;  

@end

Photo.m

#import "Photo.h"
@implementation Photo  
@synthesize photoSource = _photoSource, size = _size, index = _index, caption = _caption;  

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size {  
    return [self initWithURL:URL smallURL:smallURL size:size caption:nil];  
}  

- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size  
          caption:(NSString*)caption {  
    if (self = [super init]) {  
        _photoSource = nil;  
        _URL = [URL copy];  
        _smallURL = [smallURL copy];  
        _thumbURL = [smallURL copy];  
        _size = size;  
        _caption;
        _index = NSIntegerMax;  
    }  
    return self;  
}  

- (void)dealloc {  
    TT_RELEASE_SAFELY(_URL);  
    TT_RELEASE_SAFELY(_smallURL);  
    TT_RELEASE_SAFELY(_thumbURL);  
    TT_RELEASE_SAFELY(_caption);  
    [super dealloc];  
    
    
}  
- (void)viewDidLoad {  
    
    
}


- (NSString*)URLForVersion:(TTPhotoVersion)version {  
    if (version == TTPhotoVersionLarge) {  
        return _URL;  
    } else if (version == TTPhotoVersionMedium) {  
        return _URL;  
    } else if (version == TTPhotoVersionSmall) {  
        return _smallURL;  
    } else if (version == TTPhotoVersionThumbnail) {  
        return _thumbURL;  
    } else {  
        return nil;  
    }  
}  

@end 

AlbumController.h

#import <Three20/Three20.h>  

@interface AlbumController : TTPhotoViewController <UIActionSheetDelegate>{  
    NSArray *images;  
    UIBarButtonItem *_clickActionItem;
    UIToolbar *_toolbar;
}  
@property (nonatomic, retain) NSArray *images;  
@property (nonatomic, retain) UIBarButtonItem *_clickActionItem; 
@property (nonatomic, retain) UIToolbar *_toolbar; 
@end  

AlbumController.m

#import "AlbumController.h"  
#import "PhotoSource.h"  
#import "Photo.h"  
@implementation AlbumController  
@synthesize images;  
- (void)loadView { 
    CGRect screenFrame = [UIScreen mainScreen].bounds; 
    self.view = [[[UIView alloc] initWithFrame:screenFrame] 
                 autorelease]; 
    CGRect innerFrame = CGRectMake(0, 0, 
                                   screenFrame.size.width, 
                                   screenFrame.size.height); 
    _innerView = [[UIView alloc] initWithFrame:innerFrame]; 
    _innerView.autoresizingMask = UIViewAutoresizingFlexibleWidth| 
    UIViewAutoresizingFlexibleHeight; 
    [self.view addSubview:_innerView]; 
    _scrollView = [[TTScrollView alloc] initWithFrame:screenFrame]; 
    _scrollView.delegate = self; 
    _scrollView.dataSource = self; 
    _scrollView.backgroundColor = [UIColor blackColor]; 
    _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth| 
    UIViewAutoresizingFlexibleHeight; 
    [_innerView addSubview:_scrollView]; 
    UIBarButtonItem *_actionButton = [[UIBarButtonItem alloc] initWithImage: 
                     TTIMAGE(@"bundle://Three20.bundle/images/imageAction.png") 
                                                     style:UIBarButtonItemStylePlain target:self action:@selector 
                     (popupActionSheet)]; 
    _nextButton = [[UIBarButtonItem alloc] initWithImage: 
                   TTIMAGE(@"bundle://Three20.bundle/images/nextIcon.png") 
                                                   style:UIBarButtonItemStylePlain target:self action:@selector 
                   (nextAction)]; 
    _previousButton = [[UIBarButtonItem alloc] initWithImage: 
                       TTIMAGE(@"bundle://Three20.bundle/images/previousIcon.png") 
                                                       style:UIBarButtonItemStylePlain target:self action:@selector 
                       (previousAction)]; 
    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; 
    _toolbar.items = [NSArray arrayWithObjects: 
                      _actionButton, space, _previousButton, space, 
                      _nextButton, space, nil]; 
    [_innerView addSubview:_toolbar]; 
} 

//(Just to add an action sheet) 
//At the bottom of that codefile -- I added: 
-(void)popupActionSheet { 
    UIActionSheet *popupQuery = [[UIActionSheet alloc] 
                                 initWithTitle:nil 
                                 delegate:self 
                                 cancelButtonTitle:@"Cancel" 
                                 destructiveButtonTitle:nil 
                                 otherButtonTitles:@"Save Image",nil]; 
    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    [popupQuery showInView:self.view]; 
    [popupQuery release]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: 
(int)buttonIndex { 
    //UIImage* image = [[TTURLCache sharedCache] imageForURL:imageURL]; 
    if (buttonIndex==0){ 
        UIImage* thisImage = [[TTURLCache sharedCache] imageForURL: 
                              [_centerPhoto URLForVersion:TTPhotoVersionLarge]]; 
        UIImageWriteToSavedPhotosAlbum(thisImage, nil, nil, nil); 
        //{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL" 
    //message:[_centerPhoto URLForVersion:TTPhotoVersionLarge] delegate:self cancelButtonTitle:@"No" ,otherButtonTitles:@"Yes", nil]; 
        //[alert show];} 
    } 
} 



-(void)createPhotos {  
    images = [[NSArray alloc] initWithObjects:  
              [[[Photo alloc] initWithURL:@"bundle://14.png" smallURL:@"bundle://14.png"  
                                     size:CGSizeMake(320, 212)] autorelease],  
              [[[Photo alloc] initWithURL:@"bundle://30.png" smallURL:@"bundle://30.png"  
                                     size:CGSizeMake(320, 212)] autorelease],  
              [[[Photo alloc] initWithURL:@"bundle://back.jpeg" smallURL:@"bundle://back.jpeg"  
                                     size:CGSizeMake(319, 317)] autorelease],  
 
              nil];

}  



- (void)viewDidLoad { 
    //[self loadView];
    [self createPhotos]; // method to set up the photos array  
        self.photoSource = [[PhotoSource alloc]  
                        initWithType:PhotoSourceNormal  
                        title:@"SexyGirl"  
                        photos:images  
                        photos2:nil  
                        ];  
    
        
    
    
        
}



@end


If all you need is to save an image to the Photos album, you can use:

UIImage *myImage;
UIImageWriteToSavedPhotosAlbum(myImage,nil,nil,nil);

If this is not your problem, then I don't get it. If you don't tell us where the problem is, posting three pages worth of code is pretty useless.

0

精彩评论

暂无评论...
验证码 换一张
取 消