美文网首页
图片裁剪 旋转 转换

图片裁剪 旋转 转换

作者: mayday2024 | 来源:发表于2015-07-01 00:45 被阅读160次
         //裁剪
    
    
    
    
        -(UIImage *)getImageFromImage{
    //大图bigImage
    //定义myImageRect,截图的区域
    CGFloat imgW = self.cutimg.size.width;
    CGFloat imgH = self.cutimg.size.height;
    CGRect myImageRect = CGRectMake(0.180 * imgH, 0.09375 * imgW,0.621 *imgH,0.8437 * imgW);
    UIImage* bigImage= self.cutimg;
    
    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();
    return smallImage;
    }
    
    
    
    
    
        //裁剪图片
                UIImage *img = [self getImageFromImage];
                
                CGImageRef cgimage=img.CGImage;
                //旋转图片
                UIImage *IMG  = [UIImage imageWithCGImage:cgimage scale:1 orientation:UIImageOrientationRight];
    
    
    
    //保存到相册
                UIImageWriteToSavedPhotosAlbum(IMG, self, nil, nil);
    

    相关文章

      网友评论

          本文标题:图片裁剪 旋转 转换

          本文链接:https://www.haomeiwen.com/subject/vaaeqttx.html