pengyingh

iphone开发-图片处理-截屏

介绍两种图片的处理方法

1,截获当前的屏幕图

2,从大图中截图一小块图

iphone开发-图片处理-截屏 - 记忆的回放 - 记忆的回放的博客

【1】当前的窗口是一个view

 CGSize mSize = self.frame.size;

  //这个size定义图片的大小

  UIGraphicsBeginImageContext(mSize);

  //读取当前画布的内容
  [self.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
 
#if 0
    NSString *path = [NSHomeDirectory() stringByAppendingString:@"/tempImage.jpg"];
    NSLog(@"====%@",path);
    if ([UIImageJPEGRepresentation(tempImage, 1) writeToFile:path atomically:YES]) {
        NSLog(@"success");
    }
    else {
        NSLog(@"failed");
    }
#endif

 

【2】从大图中截取一小图

//大图bigImage

//定义myImageRect,截图的区域

CGRect myImageRect = CGRectMake(10.0, 10.0, 57.0, 57.0);

UIImage* bigImage= [UIImage imageNamed:@"picture.png"];

CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
 
 CGSize size;
 size.width = 57.0;
 size.height = 57.0;
 UIGraphicsBeginImageContext(size);
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextDrawImage(context, myImageRect, subImageRef);
 UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
 UIGraphicsEndImageContext();

smallImage就是要截图的大图中的一部分。

分类:

技术点:

相关文章:

  • 2022-02-15
  • 2021-11-04
  • 2021-11-09
  • 2022-02-09
  • 2022-02-09
  • 2021-12-07
  • 2021-05-01
  • 2021-04-03
猜你喜欢
  • 2021-10-16
  • 2021-11-27
  • 2021-06-23
  • 2021-10-26
  • 2021-11-06
  • 2021-11-22
相关资源
相似解决方案