iOS截屏

-(void)fullScreenshots{

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

    UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截圖,包括window

    [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

}

objective c 截屏代碼

-(void)save{

UIGraphicsBeginImageContext(mybackgroundview.bounds.size); //currentView 當前的view

[mybackgroundview.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);  //保存到相冊中

}截取 您想要的一層

UIGraphicsBeginImageContext(CGSizeMake(320, 300)); //currentView 當前的view

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);  //保存到相冊中

截取自定義的大小


iPhone開發應用中抓圖程序案例實現是本文要介紹的內容,主要是通過代碼來實現抓圖程序,具體實現過程,一起來看詳細代碼。


  1. //獲得屏幕圖像  
  2. - (UIImage *)imageFromView: (UIView *) theView    
  3. {  
  4.       
  5.     UIGraphicsBeginImageContext(theView.frame.size);  
  6.     CGContextRef context = UIGraphicsGetCurrentContext();  
  7.     [theView.layer renderInContext:context];  
  8.     UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();  
  9.     UIGraphicsEndImageContext();  
  10.       
  11.     return theImage;  
  12. }  
  13.  
  14. //獲得某個範圍內的屏幕圖像  
  15. - (UIImage *)imageFromView: (UIView *) theView   atFrame:(CGRect)r  
  16. {  
  17.     UIGraphicsBeginImageContext(theView.frame.size);  
  18.     CGContextRef context = UIGraphicsGetCurrentContext();  
  19.     CGContextSaveGState(context);  
  20.     UIRectClip(r);  
  21.     [theView.layer renderInContext:context];  
  22.     UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();  
  23.     UIGraphicsEndImageContext();  
  24.       
  25.     return  theImage;//[self getImageAreaFromImage:theImage atFrame:r];  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章