裁剪的UIImage看起来很拉伸,没有在正确的位置裁剪

时间:2013-07-29 18:08:26

标签: ios objective-c uiimage crop cgrectmake

我正在尝试裁剪UIImage,但是我从其他问题中找到的代码似乎不起作用。

原始图像为320x200px,我需要将裁剪后的图像设置为320x20px,并使裁剪开始比CGPoint变量“lowestPoint”高出20px。

-(UIImage*) cropImage:(UIImage*) fullImage {
  if (lowestPoint.y > 200) {
    lowestPoint.y = 200;
  }
  else if (lowestPoint.y < 0) {
    lowestPoint.y = 0;
  }

  CGRect rect = CGRectMake(0, lowestPoint.y - 20, 320,20);
  CGImageRef ref = CGImageCreateWithImageInRect([fullImage CGImage], rect);
  return [UIImage [imageWithCGImage:ref];
}

然而,返回的裁剪图像始终被拉伸,并且从未裁剪过正确的位置。

谢谢,

奥利

0 个答案:

没有答案