gpt4 book ai didi

ios - 在 UIImageView 中水平翻转 UIImage

转载 作者:行者123 更新时间:2023-11-28 21:42:34 28 4
gpt4 key购买 nike

在我的项目中,我的图像文件以 jpeg 格式存储。下面的代码“有效”,因为它不会崩溃,但我的图像不会按预期翻转。我设置了一个断点以确保代码正在运行——确实如此,但显示的图像没有翻转。我猜我错过了一些基本的东西,但它并没有突然出现在我面前。

if (self.isTimer == YES) {
// this is where images get dumped if they exist
NSMutableArray *imageArray = [[NSMutableArray alloc] init];

for (int imageNumber = 1; self.currentItem.photo != nil; imageNumber++) {
NSString *fileName = [NSString stringWithFormat:@"%@-%d", self.currentItem.photo, imageNumber];
if ([UIImage imageNamed:fileName]) {
UIImage *image = [UIImage imageNamed:fileName];
// test whether count is even or odd
if (self.currentItem.sideMultiplier.intValue == 1) {
// if there's only one side to be done, dump unflipped images in array
[imageArray addObject:image];
NSLog(@"regular image added to array");
} else {
// if there are 2 sides, determine if it's even or odd side
if (self.stretchSideMultiplierCount % 2 == 1) {
// add a unflipped image to the array
[imageArray addObject:image];
NSLog(@"regular image added to array");
} else {
// ** I want to add a FLIPPED IMAGE here
UIImage *flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUpMirrored];
[imageArray addObject:flippedImage];
NSLog(@"flipped image added to array");
}
}
NSLog(@"%@ added to imageArray", fileName);
} else {
break;
}
}

我关注了这篇文章,但没有任何反应。

How to flip UIImage horizontally?

我添加了 #import <QuartzCore/QuartzCore.h>到我的实现文件。除此之外,我不知道如何水平翻转图像。

更新:更简单的解决方案

而不是翻转 UIImage , 我翻转了 UIImageView .上面的代码我用来创建我的 imageArray现在看起来像这样:

if (self.isTimer == YES) {
// this is where images get dumped if they exist
NSMutableArray *imageArray = [[NSMutableArray alloc] init];

for (int imageNumber = 1; self.currentItem.photo != nil; imageNumber++) {
NSString *fileName = [NSString stringWithFormat:@"%@-%d", self.currentItem.photo, imageNumber];
if ([UIImage imageNamed:fileName]) {
UIImage *image = [UIImage imageNamed:fileName];
[imageArray addObject:image];
NSLog(@"image added to array");
NSLog(@"%@ added to imageArray", fileName);
} else {
break;
}
}

还有我用来翻转 UIImageView 的代码在下面的答案中。

最佳答案

问题解决了。我没有翻转 UIImage,而是翻转了 UIImageView,如下所示:

self.myImageView.transform = CGAffineTransformMakeScale(-1, 1);

关于ios - 在 UIImageView 中水平翻转 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31482842/

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