【图片旋转】很怪异的问题
从相册里面拿到一张照片,如果是自己手机上拍的图片,旋转就会出现问题,如果是外部导入的图片,旋转就正确。。实在不知道怎么回事。。附上旋转的代码。。
- (UIImage *)rotatedImage:(UIImage *)imageToRotate withRotion:(NSInteger)rotation
{
CGFloat rotationAngle = rotation * M_PI / 180;
CGSize imageSize = imageToRotate.size;
// Image size after the transformation
CGSize outputSize = [self sizeForRotatedImage:imageToRotate withRotation:rotation];
CGSize absoluteOutputSize = CGSizeAbsolute(outputSize);
UIImage *outputImage = nil;
// Create the bitmap context
UIGraphicsBeginImageContext(absoluteOutputSize);
CGContextRef imageContextRef = UIGraphicsGetCurrentContext();
// Set the anchor point to {0.5, 0.5}
CGContextTranslateCTM(imageContextRef, .5 * absoluteOutputSize.width, .5 * absoluteOutputSize.height);
// Apply rotation
CGContextRotateCTM(imageContextRef, rotationAngle);
// Draw the current image
CGContextScaleCTM(imageContextRef, 1.0, -1.0);
CGContextDrawImage(imageContextRef, (CGRect) {{-(.5 * imageSize.width), -(.5 * imageSize.height)}, imageSize}, imageToRotate.CGImage);
outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
- (CGSize)sizeForRotatedImage:(UIImage *)imageToRotate withRotation:(NSInteger)rotation
{
if (imageToRotate == nil) {
return CGSizeMake(0, 0);
}
CGFloat rotationAngle = rotation * M_PI / 180;
CGSize imageSize = imageToRotate.size;
// Image size after the transformation
CGSize outputSize = CGSizeApplyAffineTransform(imageSize, CGAffineTransformMakeRotation(rotationAngle));
return outputSize;
}
- (UIImage *)rotatedImage:(UIImage *)imageToRotate withRotion:(NSInteger)rotation
{
CGFloat rotationAngle = rotation * M_PI / 180;
CGSize imageSize = imageToRotate.size;
// Image size after the transformation
CGSize outputSize = [self sizeForRotatedImage:imageToRotate withRotation:rotation];
CGSize absoluteOutputSize = CGSizeAbsolute(outputSize);
UIImage *outputImage = nil;
// Create the bitmap context
UIGraphicsBeginImageContext(absoluteOutputSize);
CGContextRef imageContextRef = UIGraphicsGetCurrentContext();
// Set the anchor point to {0.5, 0.5}
CGContextTranslateCTM(imageContextRef, .5 * absoluteOutputSize.width, .5 * absoluteOutputSize.height);
// Apply rotation
CGContextRotateCTM(imageContextRef, rotationAngle);
// Draw the current image
CGContextScaleCTM(imageContextRef, 1.0, -1.0);
CGContextDrawImage(imageContextRef, (CGRect) {{-(.5 * imageSize.width), -(.5 * imageSize.height)}, imageSize}, imageToRotate.CGImage);
outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
- (CGSize)sizeForRotatedImage:(UIImage *)imageToRotate withRotation:(NSInteger)rotation
{
if (imageToRotate == nil) {
return CGSizeMake(0, 0);
}
CGFloat rotationAngle = rotation * M_PI / 180;
CGSize imageSize = imageToRotate.size;
// Image size after the transformation
CGSize outputSize = CGSizeApplyAffineTransform(imageSize, CGAffineTransformMakeRotation(rotationAngle));
return outputSize;
}
...全文
相关推荐
怪异测验
图像和其他媒体文件(如图片、音频或视频):增强测验的氛围和内容。5. 数据文件(如json或xml):可能存储问题和答案的数据,便于程序读取和处理。
creepy-pasta:怪异的讲故事工具
至于压缩包文件"creepy-pasta-main",这很可能是项目的根目录,包含了所有项目文件,比如HTML、CSS、JavaScript源码、图片、音频和其他资源文件。
怪异的前端应用构建框架.zip
**静态资源管理**:包括图片、字体等非文本资源的处理,如合并、压缩、重命名等。6. **自动化测试**:Jest、Mocha等工具帮助进行单元测试和集成测试,确保代码质量。7.
yaghaz:django为一个怪异系列打造的狂热场地
`static/` 和 `media/`: 分别存放应用的静态资源(如CSS、JS、图片)和用户上传的媒体文件。8.
界面怪异漂亮 vc制作不规则窗体界面
界面怪异漂亮,vc制作不规则窗体界面"这个主题聚焦于使用Visual C++(简称VC)来创建独特、视觉效果强烈的用户界面。


