yue1liang1chuan 2013-04-22 03:05 采纳率: 0%
浏览 2144
已采纳

剪裁图片导致图片向左旋转

做了一个剪裁图片的程序,调用剪裁:

UIImage* croppedImage = [self imageCrop:imageView toRect:CGRectMake(10.0, 50.0, 320, 100)];

方法:

{
    //create a context to do our clipping in
    CGRect newRect = CGRectApplyAffineTransform(rect, imageViewToCrop.transform);
    UIImage *imageToCrop = imageViewToCrop.image;
    UIGraphicsBeginImageContext(newRect.size);
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    //create a rect with the size we want to crop the image to
    //the X and Y here are zero so we start at the beginning of our
    //newly created context
    CGRect clippedRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
    CGContextClipToRect( currentContext, clippedRect);
    //draw the image to our clipped context using our offset rect
    CGContextDrawImage(currentContext, newRect, imageToCrop.CGImage);
    //pull the image from our cropped context
    UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return cropped;
}

设置图片到UIImageview的时候,图片向左旋转了。而且我也没办法让他向上旋转,怎么办?

  • 写回答

2条回答

  • lianlianbushell 2013-04-22 06:44
    关注

    如楼上所说的可能是imageOrientation属性的问题。并且你也没有正确保存scale。这样创建剪裁的图片:

    CGImageRef croppedRef = CGBitmapContextCreateImage(currentContext);
    UIImage* cropped = [UIImage imageWithCGImage:croppedRef scale:imageToCrop.scale orientation:imageToCrop.imageOrientation];
    CGImageRelease(croppedRef);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛