我有两张图片:
-map.png (1985 x 1162)(约200kb)
-map@2x.png (3969 x 2324)(约 650kb)
现在如果以这种方式加载此图像:
imageMap = [UIImage imageNamed:@"map.png"];
viewMap = [[UIView alloc] initWithFrame:CGRectMake(0, 0, imageMap.size.width, imageMap.size.height)];
viewMap.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2);
viewMap.backgroundColor = [UIColor colorWithPatternImage:imageMap];
[self.view addSubview:viewMap];
图像在 iPhone4 中加载不完整(但在 iPhone5 中运行良好),我不知道为什么。
但是如果我只放入 bundle
map@2x.png
并在
中重命名map.png
使用相同的代码,图像加载没有问题。
会发生什么?谢谢大家
编辑:
我认为问题出在 UIView
的背景设置上,因为如果我像这样修改代码:
imageMap = [UIImage imageNamed:@"map.png"];
viewMap = [[UIView alloc] initWithFrame:CGRectMake(0, 0, imageMap.size.width, imageMap.size.height)];
viewMap.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2);
// viewMap.backgroundColor = [UIColor colorWithPatternImage:imageMap];
[self.view addSubview:viewMap];
UIImageView *imageView = [[UIImageView alloc] initWithImage:imageMap];
[viewMap addSubview:imageView];
您可以正确看到图像。
最佳答案
您的图片可能太大了。你说你有
-map.png (1985 x 1162) (about 200kb)
-map@2x.png (3969 x 2324) (about 650kb)
但是,图像文件 的大小(以字节为单位)很难代表其在内存中 的大小。据我所知,加载 AxB 像素的图像会导致 A * B * 4 字节内存使用量附近的某处。在您的情况下,较小的图像约为 23MB,较大的图像约为 90MB。
考虑到 iPhone 4 有高达 512MB 的 RAM 而 iPhone 5 有 1GB,并且应用程序有权使用多少 RAM 是有限的,您可能需要重新考虑要将这些图像制作成多大。
如果您正在做类似 map 的事情,平铺可能会起作用。参见 CATiledLayer
.
关于ios - 大图像作为 UIView iOS 7 背景的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23266030/