自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone應(yīng)用程序 將圖片保存到相冊實例

移動開發(fā) iOS
本文介紹的是iPhone應(yīng)用程序 將圖片保存到相冊實例,主要介紹了對圖片的操作。先來看內(nèi)容。

iPhone應(yīng)用程序 將圖片保存到相冊實例是本文要介紹的內(nèi)容,主要是以代碼來實現(xiàn)本文要表現(xiàn)的內(nèi)容,進(jìn)入話題。有時候你的應(yīng)用需要將應(yīng)用中的圖片保存到用戶iPhone或者iTouch的相冊中。 可以使用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

要保存到用戶設(shè)備中的圖片

completionTarget

當(dāng)保存完成后,回調(diào)方法所在的對象

completionSelector

當(dāng)保存完成后,所調(diào)用的回調(diào)方法。 形式如下:

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

contextInfo

可選的參數(shù),保存了一個指向context數(shù)據(jù)的指針,它將傳遞給回調(diào)方法。

比如你可以這樣來寫一個存貯照片的方法:

  1. // 要保存的圖片   
  2.   UIImage *img = [ UIImage imageNamed:@"ImageName.png" ] ;     
  3.    
  4.   // 保存圖片到相冊中   
  5.   UIImageWriteToSavedPhotosAlbum( img, self, @selector ( image:didFinishSavingWithError:contextInfo:) , nil ) ;  

回調(diào)方法看起來可能是這樣:

  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.   }  

保存當(dāng)前視圖:

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

小結(jié):iPhone應(yīng)用程序 將圖片保存到相冊實例的內(nèi)容介紹完了,希望本文對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-26 11:13:15

iPhone PXL

2011-07-26 16:43:59

iPhone Web 服務(wù)器

2011-07-19 10:42:41

iPhone 應(yīng)用程序 模型

2011-07-19 11:12:07

iPhone 控制器

2011-07-19 10:56:15

iPhone 控制器 視圖

2011-07-21 10:47:37

iPhone Cocoa 委托

2011-07-27 17:45:29

iPhone 模擬器 圖片

2011-07-26 09:41:23

iPhone xcode Mac OS X

2010-08-27 10:41:41

iPhone核心應(yīng)用程序

2011-07-20 15:58:58

iPhone 應(yīng)用程序 生命周期

2011-07-19 14:36:32

iPhone

2011-07-27 17:30:40

iPhone Locate 定位

2011-08-12 14:54:45

iPhone委托

2011-08-05 13:49:53

iPhone 應(yīng)用 開發(fā)

2011-07-21 15:56:32

iPhone 截屏

2011-07-26 16:33:56

iPhone Delegate

2012-05-24 15:49:35

HTML5

2011-08-10 09:31:33

開發(fā)iPhone應(yīng)用程

2011-07-28 13:59:40

iPhone App

2009-12-04 10:36:29

iPhone應(yīng)用程序
點贊
收藏

51CTO技術(shù)棧公眾號