美文网首页
ios / Mac view的内容生成image

ios / Mac view的内容生成image

作者: i淳化的宁宁 | 来源:发表于2020-07-03 17:16 被阅读0次

    ios版 

    -(UIImage *)getImageViewWithView:(UIView *)view{

         UIGraphicsBeginImageContext(view.frame.size);

         [viewdrawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];

         UIImage*image =  UIGraphicsGetImageFromCurrentImageContext();

         UIGraphicsEndImageContext();

         returnimage;

    }

    Mac版

    -(NSImage*)getBackViewImage:(NSView*)baview{

        [baviewlockFocus];

        NSImage *image1 = [[NSImage alloc]initWithData:[baview dataWithPDFInsideRect:[baview bounds]]];

        [baviewunlockFocus];

        [image1lockFocus];

        //先设置 下面一个实例

        NSBitmapImageRep *bits1 = [[NSBitmapImageRep alloc]initWithFocusedViewRect:[baview bounds]];//frame

        [image1unlockFocus];

        //    1设置要用到的props属性

        NSDictionary *imageProps1 = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:NSImageCompressionFactor];

        //    转化为Data保存

        NSData *imageDat1a = [bits1 representationUsingType:NSPNGFileType properties:imageProps1];

        NSImage*img1 = [[NSImagealloc]initWithData:imageDat1a];

        returnimg1;

    }

    相关文章

      网友评论

          本文标题:ios / Mac view的内容生成image

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