IPhone apps save images to album instances

Source: Internet
Author: User

IPhoneThe application willImageSaveAlbumThe instance is the content to be introduced in this article. It mainly uses code to implement the content to be presented in this article and enter the topic. Sometimes your application needsImageSave to userIPhoneOr iTouchAlbum. You can use this class method of UIKit.

 
 
  1. void UIImageWriteToSavedPhotosAlbum (    
  2.    UIImage  *image,    
  3.    id       completionTarget,    
  4.    SEL      completionSelector,    
  5.    void     *contextInfo    
  6. );    
  7. void UIImageWriteToSavedPhotosAlbum (  
  8.    UIImage  *image,  
  9.    id       completionTarget,  
  10.    SEL      completionSelector,  
  11.    void     *contextInfo  
  12. );  

Image

To save to a user DeviceImage

CompletionTarget

After the callback method is saved

CompletionSelector

The callback method called after the data is saved. The format is as follows:

 
 
  1. - ( void ) image: ( UIImage *) image  
  2.     didFinishSavingWithError: ( NSError *) error  
  3.     contextInfo: ( void *) contextInfo; 

ContextInfo

The optional parameter stores a pointer to the context data, which is passed to the callback method.

For example, you can write a method to store photos as follows:

 
 
  1. // The image to save
  2. UIImage * img = [UIImage imageNamed: @ "ImageName.png"];
  3. // Save the image to the album
  4. UIImageWriteToSavedPhotosAlbum (img, self, @ selector (image: didFinishSavingWithError: contextInfo :), nil );

The callback method may look like this:

 
 
  1. (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error    
  2.              contextInfo:(void *)contextInfo    
  3.   {    
  4.     // Was there an error?     
  5.     if (error != NULL)    
  6.     {    
  7.       // Show error message…     
  8.      
  9.     }    
  10.     else  // No errors     
  11.     {    
  12.       // Show message image successfully saved     
  13.     }    
  14.   }    
  15. - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error  
  16.              contextInfo:(void *)contextInfo  
  17.   {  
  18.     // Was there an error?  
  19.     if (error != NULL)  
  20.     {  
  21.       // Show error message…  
  22.    
  23.     }  
  24.     else  // No errors  
  25.     {  
  26.       // Show message image successfully saved  
  27.     }  
  28.   }  

Save the current view:

 
 
  1. # Import <QuartzCore/QuartzCore. h>
  2.  
  3. UIGraphicsBeginImageContext (currentView. bounds. size); // currentView current view
  4.  
  5. [CurrentView. layer renderInContext: UIGraphicsGetCurrentContext ()];
  6.  
  7. UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext ();
  8.  
  9. UIGraphicsEndImageContext ();
  10.  
  11. UIImageWriteToSavedPhotosAlbum (viewImage, nil );

Summary:IPhoneThe application willImageSaveAlbumI hope this article will help you with the introduction of the instance!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.