美文网首页
iOS如何截屏或view生成image之后支持背景透明

iOS如何截屏或view生成image之后支持背景透明

作者: wpina | 来源:发表于2020-05-20 23:15 被阅读0次

- (UIImage *)makeImageWithView:(UIView *)orgView withSize:(CGSize)size

{

    CGFloat scale = [UIScreen mainScreen].scale;

    UIGraphicsBeginImageContextWithOptions(orgView.bounds.size, NO, scale);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    [orgView.layer renderInContext:context];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    //把像素rect 转化为点rect(如无转化则按原图像素取部分图片)

    CGFloat x= orgView.frame.origin.x*scale,y=orgView.frame.origin.y*scale,w=orgView.frame.size.width*scale,h=orgView.frame.size.height*scale;

    CGRect dianRect = CGRectMake(x, y, w, h);

    //截取部分图片并生成新图片

    CGImageRef sourceImageRef = [image CGImage];

    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, dianRect);

    UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:scale orientation:UIImageOrientationUp];

    return newImage;

}

相关文章

  • iOS如何截屏或view生成image之后支持背景透明

    - (UIImage *)makeImageWithView:(UIView *)orgView withSize...

  • android 截屏实现

    Android 截屏分为四种:View 截屏、WebView 截屏、系统截屏 和 adb 截屏 1、View 截屏...

  • Quartz 2D (2)

    1、圆形图片裁剪 2、实现手机屏幕截屏功能(把控制器中View的内容截屏生成一张新的图片) 3、图片截屏 4、图片...

  • iOS屏幕截图功能

    iOS7.0之前的系统,可以通过以下代码实现截屏功能。 iOS7.0之后,系统中封装了截屏的方法- (UIView...

  • flutter:截屏

    1.flutter-截屏组件 2.flutter-截屏插件 3.flutter-iOS原生截屏 iOS代码 4.获...

  • (最新)iOS截屏

    ios webview 截屏:ios截屏 前言:介绍一下截屏有很多种做法1:截当前屏幕内容2:截整个视图的所有内容...

  • Android 内置应用截屏方法

    Android 中,内置应用如何更好的截屏 在开发系统应用的时候,有时候需要用到截屏,因为 View.getDra...

  • ios截屏

    ios截屏

  • iOS13 UISearchBar 圆角 背景色

    iOS13及以上可以这么改。 背景色 圆角(这个就正常直接写了...) 上面的代码加一起之后长这样截屏

  • 截屏

    截屏UIGraphicsBeginImageContextWithOptions(self.view.bounds...

网友评论

      本文标题:iOS如何截屏或view生成image之后支持背景透明

      本文链接:https://www.haomeiwen.com/subject/pmzoohtx.html