Ios 獲取設備截屏圖片

?截取當前屏幕

-(UIImage*)imageFromView : (UIView*)view

{

UIGraphicsBeginImageContext(CGSizeMake(appWith,appHight-50));

//renderInContext呈現接受者及其子范圍到指定的上下文

[view.layerrenderInContext:UIGraphicsGetCurrentContext()];

//返回一個基于當前圖形上下文的圖片

UIImage*extractImage =UIGraphicsGetImageFromCurrentImageContext();

//移除棧頂的基于當前位圖的圖形上下文

UIGraphicsEndImageContext();

//以png格式返回指定圖片的數據

NSData*imageData =UIImagePNGRepresentation(extractImage);

UIImage*imge = [UIImageimageWithData:imageData];

----------------------------------至此已經得到需要的圖片------------------------------------------


主要代碼


//根據自己的需要編輯尺寸

floatoriginX =0.0;

floatoriginY =0.0;

floatwidth =appWith;

floatheight =450;

CGRectrect1 =CGRectMake(originX , originY, width ,height);

UIImage* Scrimg = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([imgeCGImage], rect1)];

returnScrimg;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容