ios 截屏(代碼),ios截屏代碼

來源:互聯網
上載者:User

ios 截屏(代碼),ios截屏代碼

//1.首先在storyboard中拖一些控制項,包括UIButton控制項,將UIButton控制項拖線到控制器中(方法、CutImage)

//2.在CutImage方法中調用NSTimer方法

- (IBAction)CutImage:(UIButton *)sender {

  NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 targer:self  selector:@selector(clipImage) userInfo:nil repeats:NO];

}

//3.調用clipImage方法

-(void)clipImage

{

  //1.建立圖形上下為難

  UIGraphicsBeginImageCOntextWithOptions(self.view.bounds.size,NO,0.0);

  //2.調取方法截屏(截取的是全屏)

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

  //3.獲得當前的圖片

  UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

  //4.結束圖形上下文

  UIGraphicsEndImgeContext();

   //5.列印資料

   NSData *data =UIImagePNGRepresentation(newImage);

  [data writeToFile:@"/User/apple/DeskTop/new1.png" atomically:YES];

  

}


怎在ios裡面?用代碼實現

解決方案很多!//螢幕 UIImage*snapshot; CGImageRefcgScreen=UIGetScreenImage(); if(cgScreen){ snapshot=[UIImageimageWithCGImage:cgScreen]; CGImageRelease(cgScreen); } CGRectrect=CGRectMake(0,125,640,750);//建立要剪下的矩形框這裡你可以自己修改 UIImage*res=[UIImageimageWithCGImage:CGImageCreateWithImageInRect([snapshotCGImage],rect)] //res就是後的UIImage
 
iphone怎?iOS方法介紹

但是其實它還有更多功能,比如。首先按住home鍵,不要鬆開(因為你要進行遊戲的話鬆開就退出程式了) 。接下來就是輕輕按下關機鍵(電源鍵也叫待機鍵),這時候就能聽到拍照的聲音,然後你就可以在手機相簿中查看照片了。該方法是適用諸多iOS裝置的,比如iTouch,iPad都是可以用這種方法即時,現在不妨去一試哦。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.