UIGraphics

//等比缩放

- (UIImage*)scaleImage:(UIImage*)imagetoScale:(float)scaleSize {

    UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));

    [imagedrawInRect:CGRectMake(0,0, image.size.width* scaleSize, image.size.height* scaleSize)];

    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnscaledImage;

}

//自定义大小

- (UIImage*)reSizeImage:(UIImage*)imagetoSize:(CGSize)reSize {

    UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));

    [imagedrawInRect:CGRectMake(0,0, reSize.width, reSize.height)];

    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnreSizeImage;

}

//UIView转image

-(UIImage*)captureView:(UIView*)theView {

    CGRectrect = theView.frame;

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [theView.layerrenderInContext:context];

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnimg;

}

//合并图片

- (UIImage*)addImage:(UIImage*)image1toImage:(UIImage*)image2{

    UIGraphicsBeginImageContext(CGSizeMake(image2.size.width, image2.size.height));

    [image2drawInRect:CGRectMake(0,0, image2.size.width, image2.size.height)];

    [image1drawInRect:CGRectMake(0,image2.size.height-100, image1.size.width, image1.size.height)];

    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return  resultingImage;

}

//  https://www.jianshu.com/p/6874e6c4fec6

你可能感兴趣的:(UIGraphics)