UIImage合成

来源:互联网 发布:java爬虫抓取微博数据 编辑:程序博客网 时间:2024/06/10 18:15

前两个参数为两张合成的图片,第三个参数为第一张图片在第二张图片上合成的位置

- (UIImage *)composeImage:(UIImage *)subImage toImage:(UIImage *)superImage atFrame:(CGRect)frame

{

   CGSize superSize = superImage.size;

   CGFloat widthScale = frame.size.width /self.cameraView.frame.size.width;

   CGFloat heightScale = frame.size.height /self.cameraView.frame.size.height;

   CGFloat xScale = frame.origin.x /self.cameraView.frame.size.width;

   CGFloat yScale = frame.origin.y /self.cameraView.frame.size.height;

   CGRect subFrame = CGRectMake(xScale * superSize.width, yScale * superSize.height, widthScale * superSize.width, heightScale * superSize.height);

    

    UIGraphicsBeginImageContext(superSize);

    [superImagedrawInRect:CGRectMake(0,0, superSize.width, superSize.height)];

    [subImagedrawInRect:subFrame];

    __autoreleasingUIImage *finish =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

   return finish;

}

0 0
原创粉丝点击