Using CoreImage to filter an image results in image rotation(使用 CoreImage 过滤图像会导致图像旋转)
问题描述
感谢阅读.
我正在尝试在 iOS 5 中使用 CoreImage 来更改图像的外观.问题是现有图像在此过程中似乎丢失了其方向信息并最终旋转了 90 度.
I'm trying to use CoreImage in iOS 5 to alter the appearance of an image. The problem is that the existing image appears to lose its orientation information during the process and ends up rotated by 90 degrees.
代码如下:
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *img = [CIImage imageWithCGImage:imageView.image.CGImage];
CIFilter *adjustFilter = [CIFilter filterWithName:@"CIHighlightShadowAdjust"];
[adjustFilter setDefaults];
[adjustFilter setValue:img forKey:kCIInputImageKey];
[adjustFilter setValue:[NSNumber numberWithFloat:0.3] forKey:@"inputShadowAmount"];
CIImage *adjustedImage = [adjustFilter valueForKey:kCIOutputImageKey];
UIImage *newPtImage = [UIImage imageWithCGImage:[context adjustedImage fromRect:adjustedImage.extent]];
imageView.image = newPtImage;
原始图像通常来自相机拍摄的图像,但并非总是如此.
The original image generally comes from one taken by the camera, but not always.
希望有人能提供帮助.
罗伯.
推荐答案
其实我的问题的解决方案很简单.由于 CGImage 失去了它的方向和比例因子,我只需要添加
Actually, the solution to my issue turned out to be quite simple. Since the CGImage loses its orientation and scale factors, I simply needed to add
UIImageOrientation originalOrientation = imageView.image.imageOrientation;
CGFloat originalScale = imageView.image.scale;
在代码的早期,然后用这个代替 [UIImage imageWithCGImage:]
early in the code and then used this instead of [UIImage imageWithCGImage:]
UIImage *newPtImage = [UIImage imageWithCGImage:img2 scale:originalScale orientation:originalOrientation];
也感谢您的建议.
这篇关于使用 CoreImage 过滤图像会导致图像旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 CoreImage 过滤图像会导致图像旋转
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
