旋转 UIImage 的问题
我的代码如下。有谁知道发生了什么事?
抱歉信息不完整。图像就这样消失了!
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *imCaptured = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
CGImageRef cgirCropped = CGImageCreateWithImageInRect(imCaptured.CGImage, CGRectMake(700.0f, 430.0f, 650.0f, 650.0f));
UIImage *imCropped = [UIImage imageWithCGImage:cgirCropped];
UIGraphicsBeginImageContext(imCropped.size);
CGContextRef cgcrRotation = UIGraphicsGetCurrentContext();
switch (imCaptured.imageOrientation) {
case UIImageOrientationUp:
CGContextRotateCTM(cgcrRotation, (180 * M_PI / 180));
break;
case UIImageOrientationDown:
break;
case UIImageOrientationLeft:
break;
case UIImageOrientationRight:
CGContextRotateCTM(cgcrRotation, (90 * M_PI / 180));
break;
}
[imCropped drawAtPoint:CGPointMake(0.0f, 0.0f)];
[imvPreview setImage:UIGraphicsGetImageFromCurrentImageContext()];
}
My code is below. Does anyone know what is happening?
Sorry about the incomplete information. The image just disappears!
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *imCaptured = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
CGImageRef cgirCropped = CGImageCreateWithImageInRect(imCaptured.CGImage, CGRectMake(700.0f, 430.0f, 650.0f, 650.0f));
UIImage *imCropped = [UIImage imageWithCGImage:cgirCropped];
UIGraphicsBeginImageContext(imCropped.size);
CGContextRef cgcrRotation = UIGraphicsGetCurrentContext();
switch (imCaptured.imageOrientation) {
case UIImageOrientationUp:
CGContextRotateCTM(cgcrRotation, (180 * M_PI / 180));
break;
case UIImageOrientationDown:
break;
case UIImageOrientationLeft:
break;
case UIImageOrientationRight:
CGContextRotateCTM(cgcrRotation, (90 * M_PI / 180));
break;
}
[imCropped drawAtPoint:CGPointMake(0.0f, 0.0f)];
[imvPreview setImage:UIGraphicsGetImageFromCurrentImageContext()];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有测试过代码,但我认为它绕着原点旋转,所以你也需要翻译,比如:
I haven't tested the code, but I think it rotates around the origin, so you need to translate as well, something like: