【问题标题】:Image cropping giving wrong part of the image图像裁剪给出图像的错误部分
【发布时间】:2012-06-04 14:08:49
【问题描述】:

我编写了裁剪图像的代码,但我得到的是图像的另一部分,而不是给定的矩形。

CGImageRef cr = CGImageCreateWithImageInRect([imageCrop.image CGImage], rectangle.frame);
    imageCrop.frame=rectangle.frame;
    imageCrop.image = [[[UIImage alloc] initWithCGImage:cr] autorelease];
    CGImageRelease(cr);

【问题讨论】:

    标签: iphone ios uiimageview uiimage core-animation


    【解决方案1】:

    如果您收到图像的另一部分,可能是因为您提供的UIImageimageOrientation 属性值。在裁剪前考虑图像方向。

    图像方向会影响图像数据在绘制时的显示方式。默认情况下,图像以“向上”方向显示。但是,如果图像具有关联的元数据(例如 EXIF 信息),则此属性包含该元数据指示的方向。有关此属性的可能值列表,请参阅UIImageOrientation

    【讨论】:

    • 图像方向应该是什么?
    • @IdreesAshraf 我用其他信息更新了我的答案
    【解决方案2】:
     //  Try using following line of code-
    
        CGImageRef cr = CGImageCreateWithImageInRect([imageCrop.image CGImage], rectangle.frame);
        imageCrop.image =[UIImage imageWithCGImage:croppedCGImage scale:1.0f orientation:self.imageOrientation];
         CGImageRelease(cr);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      相关资源
      最近更新 更多