gpt4 book ai didi

iphone - 图像旋转不正确

转载 作者:行者123 更新时间:2023-11-28 22:45:16 24 4
gpt4 key购买 nike

旋转我正在尝试将图像旋转 90 度。它在没有旋转的情况下工作,但是当我旋转和平移时它不显示。我做错了什么?

            NSString *filePath = [[NSBundle mainBundle] pathForResource:@"check" ofType:@"jpg"];
UIImage *newImage = [[UIImage alloc] initWithContentsOfFile:filePath];

UIGraphicsBeginImageContext(newImage.size);
//CGContextRef c = UIGraphicsGetCurrentContext();

CGContextTranslateCTM(UIGraphicsGetCurrentContext(), newImage.size.width, 0);
//CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, newImage.size.width);
//CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
CGContextRotateCTM(UIGraphicsGetCurrentContext(), 90);
CGRect imageRect = CGRectMake(0, 0, newImage.size.height, newImage.size.width);
CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, newImage.CGImage);
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

ImageView.image = viewImage;

最佳答案

我建议使用 ImageView 并像这样使用它的转换:

UIImage *newImage = [[UIImage alloc] initWithContentsOfFile:filePath];
UIImageView *newImageView = [[UIImageView alloc] initWithImage:newImage];
newImageView.transform = CGAffineTransformMakeRotation(M_PI_2);

关于iphone - 图像旋转不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13362319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com