ios 截图 ,图片合成,画纯色UIimage

1、截取部分UIImage

C代码   收藏代码
  1. -(UIImage *)clipImageFromImage:(UIImage *)orgImage  Rect:(CGRect)clipRect{  
  2.     CGImageRef imageRef = orgImage.CGImage;  
  3.     CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, clipRect);  
  4.     CGSize size;  
  5.     size = clipRect.size;  
  6.     UIGraphicsBeginImageContext(size);  
  7.     CGContextRef context = UIGraphicsGetCurrentContext();  
  8.     CGContextDrawImage(context, clipRect, subImageRef);  
  9.     UIImage* clipImage = [UIImage imageWithCGImage:subImageRef];  
  10.     CGImageRelease(subImageRef);  
  11.     UIGraphicsEndImageContext();  
  12.     return clipImage;  
  13. }  

 

2图片合成:

Java代码   收藏代码
  1. - (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {  
  2.     UIGraphicsBeginImageContext(image1.size);  
  3.     [image1 drawInRect:CGRectMake(00, image1.size.width, image1.size.height)];  
  4.     [image2 drawInRect:CGRectMake(00, image2.size.width, image2.size.height)];  
  5.     UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();  
  6.     UIGraphicsEndImageContext();  
  7.     return resultingImage;  
  8. }  

 

 3画纯色UIImage

Java代码   收藏代码
  1. CGSize imageSize = CGSizeMake(5050);  
  2. UIGraphicsBeginImageContextWithOptions(imageSize, 0, [UIScreen mainScreen].scale);  
  3. [[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0] set];  
  4. UIRectFill(CGRectMake(00, imageSize.width, imageSize.height));  
  5. UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();  
  6. UIGraphicsEndImageContext();  

1、截取部分UIImage

C代码   收藏代码
  1. -(UIImage *)clipImageFromImage:(UIImage *)orgImage  Rect:(CGRect)clipRect{  
  2.     CGImageRef imageRef = orgImage.CGImage;  
  3.     CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, clipRect);  
  4.     CGSize size;  
  5.     size = clipRect.size;  
  6.     UIGraphicsBeginImageContext(size);  
  7.     CGContextRef context = UIGraphicsGetCurrentContext();  
  8.     CGContextDrawImage(context, clipRect, subImageRef);  
  9.     UIImage* clipImage = [UIImage imageWithCGImage:subImageRef];  
  10.     CGImageRelease(subImageRef);  
  11.     UIGraphicsEndImageContext();  
  12.     return clipImage;  
  13. }  

 

2图片合成:

Java代码   收藏代码
  1. - (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {  
  2.     UIGraphicsBeginImageContext(image1.size);  
  3.     [image1 drawInRect:CGRectMake(00, image1.size.width, image1.size.height)];  
  4.     [image2 drawInRect:CGRectMake(00, image2.size.width, image2.size.height)];  
  5.     UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();  
  6.     UIGraphicsEndImageContext();  
  7.     return resultingImage;  
  8. }  

 

 3画纯色UIImage

Java代码   收藏代码
  1. CGSize imageSize = CGSizeMake(5050);  
  2. UIGraphicsBeginImageContextWithOptions(imageSize, 0, [UIScreen mainScreen].scale);  
  3. [[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0] set];  
  4. UIRectFill(CGRectMake(00, imageSize.width, imageSize.height));  
  5. UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();  




  6. UIGraphicsEndImageContext();  

4.把图片绘图到对应区域,在中间

- (UIImage*)clipImageFromImage:(UIImage *)orgImage Rect:(CGRect)targetRect

{

    UIGraphicsBeginImageContextWithOptions(targetRect.size, NO, [UIScreen mainScreen].scale);

    [orgImage drawInRect:CGRectMake((targetRect.size.width-orgImage.size.width)/2.0, (targetRect.size.height-orgImage.size.height)/2.0, orgImage.size.width, orgImage.size.height)];

    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return resultingImage;

}


你可能感兴趣的:(ios 截图 ,图片合成,画纯色UIimage)