Take photo and save photo to iphone photos library

1。保存图片

 

UIImageWriteToSavedPhotosAlbum

Adds the specified image to the user’s Camera Roll album.

void UIImageWriteToSavedPhotosAlbum (

   UIImage  *image,

   id       completionTarget,

   SEL      completionSelector,

   void     *contextInfo

);

Parameters

image

The image to write to the Camera Roll album.

completionTarget

Optionally, the object whose selector should be called after the image has been written to the Camera Roll album.

completionSelector

The method selector, of the completionTarget object, to call. This optional method should conform to the following signature:

– (void)               image: (UIImage *) image

 

    didFinishSavingWithError: (NSError *) error

 

                 contextInfo: (void *) contextInfo;

 

contextInfo

An optional pointer to any context-specific data that you want passed to the completion selector.

Discussion

When used with an image picker controller, you would typically call this function within yourimagePickerController:didFinishPickingMediaWithInfo: delegate method implementation.

The use of the completionTarget, completionSelector, and contextInfo parameters is optional and necessary only if you want to be notified asynchronously when the function finishes writing the image to the user’s Camera Roll or Saved Photos album. If you do not want to be notified, passnil for these parameters.

When used on an iOS device without a camera, this method adds the image to the Saved Photos album rather than to the Camera Roll album.

Availability

  • Available in iOS 2.0 and later.

See Also

  • UISaveVideoAtPathToSavedPhotosAlbum

Declared In

UIImagePickerController.h

 

 

说明:后面三个参数是可选的。如果需要在图片保存成功后进行异步的通知,则后面三个参数是必需的。否则,传递nil。

不太明白 Saved Photos album与Camera Roll album间的区别。。。图片库与相机胶卷。。。感觉在机子里是一回事。

拍照时点击左下角的button会切换到图片库啊???

 

下面的保存视频的方法与保存图片的方法非常类似,用法基本一样。

 

下面贴点代码:

(1)最常用的方法

 

UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);

(2)用AVFoundation库

 There`s much more fast than UIImageWriteToSavedPhotosAlbum way to do it using iOS 4.0+ AVFoundation framework

 

 

   ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
    if (error) {
    // TODO: error handling
    } else {
    // TODO: success handling
    }
}];
[library release];

 

主要是以上两种保存图片的方法

 

具体点:

    //in the .h file put:

NSMutableArray *myPhotoArray;


///then in the .m

- (void) viewDidLoad {

 myPhotoArray = [[NSMutableArray alloc]init];



}

//However Your getting images

- (void) someOtherMethod { 

 UIImage *someImage = [your prefered method of using this];
[myPhotoArray addObject:someImage];

}

-(void) saveMePlease {

//Loop through the array here
for (int i=0:i<[myPhotoArray count]:i++){
         NSString *file = [myPhotoArray objectAtIndex:i];
         NSString *path = [get the path of the image like you would in DOCS FOLDER or whatever];
         NSString *imagePath = [path stringByAppendingString:file];
         UIImage *image = [[[UIImage alloc] initWithContentsOfFile:imagePath]autorelease];

         //Now it will do this for each photo in the array
         UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        }
}

 

 

 

 

 

 

 

2。保存视频

UISaveVideoAtPathToSavedPhotosAlbum

Adds the movie at the specified path to the user’s Camera Roll album.

void UISaveVideoAtPathToSavedPhotosAlbum (

   NSString  *videoPath,

   id        completionTarget,

   SEL       completionSelector,

   void      *contextInfo

);

Parameters

videoPath

The filesystem path to the movie file you want to save to the Camera Roll album.

completionTarget

Optionally, the object whose selector should be called after the movie has been written to the Camera Roll album.

completionSelector

The method selector, of the completionTarget object, to call. This optional method should conform to the following signature:

– (void)               video: (NSString *) videoPath

 

    didFinishSavingWithError: (NSError *) error

 

                 contextInfo: (void *) contextInfo;

 

contextInfo

An optional pointer to any context-specific data that you want passed to the completion selector.

Discussion

When used with an image picker controller, you would typically call this function within yourimagePickerController:didFinishPickingMediaWithInfo: delegate method implementation.

Before calling this function, call theUIVideoAtPathIsCompatibleWithSavedPhotosAlbum function to determine if it is possible to save movies to the Camera Roll album. For a code example, refer toCamera Programming Topics for iOS.

The use of the completionTarget, completionSelector, and contextInfo parameters is optional and necessary only if you want to be notified asynchronously when the function finishes writing the movie to the user’s Camera Roll or Saved Photos album. If you do not want to be notified, passnil for these parameters.

When used on an iOS device without a camera, this method adds the movie to the Saved Photos album rather than to the Camera Roll album.

Availability

  • Available in iOS 3.1 and later.

See Also

  • UIImageWriteToSavedPhotosAlbum
  • UIVideoAtPathIsCompatibleWithSavedPhotosAlbum

Declared In

UIImagePickerController.h

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s