iOS interface generation pictures

      In our normal development, we often generate pictures from a certain interface of the APP and share them on WeChat, Moments and other platforms. Some development teams obtain a picture through the background interface, and the APP obtains it directly. However, there are also some backends who find it troublesome to draw and require the APP to do it themselves. At this time, it is necessary to use iOS graphics drawing.

//Using this method will not blur, and the image will be obtained based on the screen density calculation. Just pass in the view you need to convert into an image.

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

    UIImage *imageRet = [[UIImage alloc]init];

    //UIGraphicsBeginImageContextWithOptions(区域大小, 是否是非透明的, 屏幕密度);

    UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, [UIScreen mainScreen].scale);

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    imageRet = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return imageRet;

}

Guess you like

Origin blog.csdn.net/geniusyan/article/details/132190689