CGImageCreateWithImageInRect没有正确裁剪

时间:2014-11-19 22:56:00

标签: ios uiimage

我有一张想要切成两半的图像,因此它只是图像的下半部分。我一直试图通过裁剪图像来做到这一点,但它似乎没有做任何事情,图像大小相同,无论我应用什么作物。我的实施中有什么问题吗?我的代码如下。

NSString *imageString = [NSString stringWithFormat:@"grey_%@", imagePath];

greyImage = [UIImage imageNamed:imageString];
int width = greyImage.size.width;
int height = greyImage.size.height;

CGRect myRect = CGRectMake(0, 0, width, height / 2);
CGImageRef ref = CGImageCreateWithImageInRect([greyImage CGImage], myRect);
cropGrey = [UIImage imageWithCGImage:ref scale:greyImage.scale orientation:greyImage.imageOrientation];
CGImageRelease(ref);

[self addCreatedImage:greyImage toSubview:badgeView atX:30 atY:30 atWidth:badgeViewWidth - 60 atHeight:(badgeViewWidth - 60) / 2 isRounded:NO];

无论是使用greyImage还是cropGrey,图像都显示完全相同。我不知道为什么会这样,任何帮助都会受到赞赏。谢谢!

0 个答案:

没有答案