1

在应用程序中,用户拍照,然后将照片分配给一个按钮,他们可以点击该按钮重新拍摄照片。我无法让它为视网膜图像工作。

这是代码:

BodyData *lastPerson = (BodyData*)[ReadPerson readLastEntry];
CGRect frame = self.frontImage.frame;
CGSize doubleSize = CGSizeMake(self.frontImage.frame.size.width * 2, self.frontImage.frame.size.height * 2);

NSLog(@"frame is: %@", NSStringFromCGRect(self.frontImage.frame));

UIImage *frontPhoto = [[UIImage imageWithData:[lastPerson readPhotoOfSize:Full withAngle:Front withPlaceholderIfNoImage:NO]] resizeTo: doubleSize]; // Custom category to resize image

if (frontPhoto) {
    [[self.frontImage imageView] setContentMode: UIViewContentModeScaleAspectFit];
    [self.frontImage setImage:frontPhoto forState:UIControlStateNormal];
    [self.frontImage setImage:[frontPhoto darkenedImage] forState:UIControlStateHighlighted];
    [self.frontImage setFrame:frame];
    [self.frontImage.imageView setFrame:frame];
    NSLog(@"frontimage sized to: %@", NSStringFromCGSize(self.frontImage.frame.size));
}

日志输出为:

frame is: {{20, 145}, {129, 172}}
frontimage sized to: {258, 344}

自动布局已启用,但图像不会在 viewdidload 时更改,而是在照片已拍摄的通知中更改。

如何获得视网膜质量图像作为按钮的值?我已经添加了所有框架调整大小的东西,因为按钮正在调整大小并且我试图覆盖它,但即使这样也不起作用。

所以按钮应该是:{129, 172},带有@2x 版本的照片。但它是 {258, 344},带有 @1x 版本的照片。

4

2 回答 2

1

我的建议是调整图像的比例:

UIImage *otherImage;
UIImage *image              = [[UIImage alloc] initWithCGImage:otherImage.CGImage
                                                         scale:otherImage.scale * 2.0f
                                                   orientation:otherImage.imageOrientation];
于 2013-11-13T09:06:42.987 回答
0

明确一件事。如果您有一个 10x10 像素大小的按钮,那么您必须使用 10x10 大小的图像用于非视网膜显示和 20x20 大小的图像用于视网膜显示。

您说照片是用户拍摄的,然后设置为按钮。如果要达到视网膜质量,您必须对图像进行一些缩放才能将其设置为视网膜图像。

于 2013-11-13T09:06:12.837 回答