【发布时间】:2024-01-04 00:00:01
【问题描述】:
我已经对 UIButton 进行了测试,按钮应该显示来自相机的捕获缓冲区,所以我将为 UIButton 设置图像和背景图像。 从相机捕获的数据中,我设置了图像和背景图像,图像显示是正确的,但是当我按下按钮时,背景图像已经旋转了 90 度。 测试代码是:
NSData *imagedata = [AVCaptureStillImageOutput jpegStillImageNSDataRepesentation:buffer];
UIImage *image = [[UIImage alloc] initWithData:imagedata];
[galleryBtn setImage:image forState:UIControlStateNormal];
[galleryBtn setBackgroundImage:image forState:UIControlStateNormal];
但是当我从 png 数据创建 UIImage 时,显示是正确的并且没有旋转。
UIImage *image = [UIImage imageNamed:@"0.png"];
请帮帮我。
【问题讨论】:
-
我没有在 UIButton 上方使用 UIImageView,并设置 UIIMageView 内容。但是我不知道为什么UIButton的图片和背景图片会显示不同,即使我给这个UIButton设置了相同的UIImage。
-
我检查了从相机 jpg 结果创建的 UIImage,旋转不是 0,是 3。
-
我尝试了另一种方法来解决这个问题。从 Graphics 创建一个新的 UIImage。然后将图像和背景图像设置为 UIButton。
标签: ios uiimage uibutton rotation setbackground