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.
- void UIImageWriteToSavedPhotosAlbum (
- UIImage *image,
- id completionTarget,
- SEL completionSelector,
- void *contextInfo
- );
- void UIImageWriteToSavedPhotosAlbum (
- UIImage *image,
- id completionTarget,
- SEL completionSelector,
- void *contextInfo
- );
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:
- - ( void ) image: ( UIImage *) image
- didFinishSavingWithError: ( NSError *) error
- 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:
- // The image to save
- UIImage * img = [UIImage imageNamed: @ "ImageName.png"];
- // Save the image to the album
- UIImageWriteToSavedPhotosAlbum (img, self, @ selector (image: didFinishSavingWithError: contextInfo :), nil );
The callback method may look like this:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
- contextInfo:(void *)contextInfo
- {
- // Was there an error?
- if (error != NULL)
- {
- // Show error message…
-
- }
- else // No errors
- {
- // Show message image successfully saved
- }
- }
- - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
- contextInfo:(void *)contextInfo
- {
- // Was there an error?
- if (error != NULL)
- {
- // Show error message…
-
- }
- else // No errors
- {
- // Show message image successfully saved
- }
- }
Save the current view:
- # Import <QuartzCore/QuartzCore. h>
-
- UIGraphicsBeginImageContext (currentView. bounds. size); // currentView current view
-
- [CurrentView. layer renderInContext: UIGraphicsGetCurrentContext ()];
-
- UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext ();
-
- UIGraphicsEndImageContext ();
-
- UIImageWriteToSavedPhotosAlbum (viewImage, nil );
Summary:IPhoneThe application willImageSaveAlbumI hope this article will help you with the introduction of the instance!