iphone - Three20 to save images?(Close) -


i'm new iphone application developer,i need create 1 application photo gallery.now problem donno how save image photo album.

i have build project no error no werning me.in simulator can run project.

but cnt see things add.hope can 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 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];            (int = 0; < _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];            (int = 0; < _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;            (int = 0; < _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 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 add action sheet)  //at bottom of codefile -- 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 set photos array           self.photosource = [[photosource alloc]                           initwithtype:photosourcenormal                           title:@"sexygirl"                           photos:images                           photos2:nil                           ];        }    @end 

if need save image photos album, can use:

uiimage *myimage; uiimagewritetosavedphotosalbum(myimage,nil,nil,nil); 

if not problem, don't it. if don't tell problem is, posting 3 pages worth of code pretty useless.


Comments