iphone - iOS 4.3 上的图像负畸变

标签 iphone ios image ipad

我想,为什么当我在 iPad 模拟器和设备上使用 iOS 4.3 时,我的应用程序会出现图像失真。看一下截图。相同的图像在 iOS 5.1 模拟器和设备上正常显示。看第二个屏幕截图...我应该如何处理这个问题?也许可以在显示 JPEG 之前编写一些代码? Distorted on iOS 4.3 Normal on iOS 5.1 不幸的是,我必须修复它,因为我的应用程序必须以某种方式在 iOS 4.3 上运行。

这是一个方法,用于生成拇指:

- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
UIImage *newImage = nil;        
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);

if (CGSizeEqualToSize(imageSize, targetSize) == NO) 
{
    CGFloat widthFactor = targetWidth / width;
    CGFloat heightFactor = targetHeight / height;

    if (widthFactor > heightFactor) 
        scaleFactor = widthFactor; // scale to fit height
    else
        scaleFactor = heightFactor; // scale to fit width
    scaledWidth  = width * scaleFactor;
    scaledHeight = height * scaleFactor;

    // center the image
    if (widthFactor > heightFactor)
    {
        thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; 
    }
    else 
        if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
}       

UIGraphicsBeginImageContext(targetSize); // this will crop

CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width  = scaledWidth;
thumbnailRect.size.height = scaledHeight;

[sourceImage drawInRect:thumbnailRect];

newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil) 
    NSLog(@"could not scale image");

//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}

但是,如果我不使用它来准备图像,它仍然是负数,但运行速度会更慢,因为图像会自动调整大小。

该方法用于显示图像:

-(void) setImage:(UIImage*)image forState:(UIControlState) state
{
[self.buttonView setImage:image forState:state];
}

这样:

[current setImage:thumb forState:UIControlStateNormal];

是的,我忘了提及,这些家伙只是 View Controller 的自定义按钮。

最佳答案

我在 4.3 上遇到了同样的问题 - 原来图像是用 CMYK 颜色保存的。切换到 RGB 并重新保存图像使问题消失。

关于iphone - iOS 4.3 上的图像负畸变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10076790/

相关文章:

iphone - 在 UINavigation 类型的应用程序中,如何在 View Controller 之间进行通信?

iphone - 如何更新 iOS 应用程序(文件除外)

iOS 10 : Fatal Exception: NSInternalInconsistencyException Could not load NIB in bundle

iphone - 防止从 iphone sdk 中的 uiimage 拉伸(stretch)图像

javascript - 让 holder.js 与 Angular 一起工作

css - 在较小的 div 中垂直居中图像(多个缩放图像,多个 div)

iphone - UITableView 图像 - 保存两个图像或调整大小?

iphone - 如何在 iOS 中更改 URL 中的内容?

objective-c - 为什么在此代码中通过另一个对象调用时 Core Motion 更新不起作用?

ios - 禁止用户在 UIPageViewController 上仅向特定方向滑动?