iOS 获取屏幕某个区域的截图
2016-11-21 18:14
239 查看
-(void)fullScreenshots{
UIWindow *screenWindow = [[UIApplicationsharedApplication]
keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window
[screenWindow.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
float originX =_sampleView.frame.origin.x;
float originy =_sampleView.frame.origin.y;
float width =_sampleView.frame.size.width;
float height =_sampleView.frame.size.height;
//你需要的区域起点,宽,高;
CGRect rect1 =CGRectMake(originX , originy , width , height);
UIImage * imgeee = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([viewImageCGImage],
rect1)];
UIImageView *snapImg = [[UIImageViewalloc]
initWithFrame:CGRectMake(0,200,
170,170)];
snapImg.backgroundColor = [UIColorredColor];
snapImg.image = imgeee;
[self.viewaddSubview:snapImg];
}
或者:
- (void)snapAction:(UIButton *)btn {
UIImage *image = [self
snapshot:_sampleView];
UIImageView *snapImg = [[UIImageView
alloc] initWithFrame:CGRectMake(0,
200, 170,
170)];
snapImg.layer.borderWidth =
1;
snapImg.image = image;
[self.view
addSubview:snapImg];
}
- (UIImage *)snapshot:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size,YES,0);
[view drawViewHierarchyInRect:view.bounds
afterScreenUpdates:YES];
UIImage *image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
UIWindow *screenWindow = [[UIApplicationsharedApplication]
keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window
[screenWindow.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
float originX =_sampleView.frame.origin.x;
float originy =_sampleView.frame.origin.y;
float width =_sampleView.frame.size.width;
float height =_sampleView.frame.size.height;
//你需要的区域起点,宽,高;
CGRect rect1 =CGRectMake(originX , originy , width , height);
UIImage * imgeee = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([viewImageCGImage],
rect1)];
UIImageView *snapImg = [[UIImageViewalloc]
initWithFrame:CGRectMake(0,200,
170,170)];
snapImg.backgroundColor = [UIColorredColor];
snapImg.image = imgeee;
[self.viewaddSubview:snapImg];
}
或者:
- (void)snapAction:(UIButton *)btn {
UIImage *image = [self
snapshot:_sampleView];
UIImageView *snapImg = [[UIImageView
alloc] initWithFrame:CGRectMake(0,
200, 170,
170)];
snapImg.layer.borderWidth =
1;
snapImg.image = image;
[self.view
addSubview:snapImg];
}
- (UIImage *)snapshot:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size,YES,0);
[view drawViewHierarchyInRect:view.bounds
afterScreenUpdates:YES];
UIImage *image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
相关文章推荐
- iOS 获取屏幕某个区域的截图-b
- 远程获取iOS设备的屏幕截图
- iOS 快速获取屏幕截图的方法
- iOS 获取屏幕截图和缩放、裁剪图片
- IOS中屏幕截图(区域截图)
- iOS 关于屏幕截图,获取webView高度,截取长图
- ios 获取屏幕的属性和宽度
- IOS获取屏幕分辨率
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- 从FrameBuffer中获取Android屏幕截图
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- IOS获取屏幕分辨率
- ios 获取一个view上的图片,iphone混合图片 合成图片 任意范围截图 截屏
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- ios 获取当前屏幕的方向 隐藏状态栏
- ios 获取当前屏幕的方向 隐藏状态栏
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- 从FrameBuffer中获取Android屏幕截图
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形