2011-01-07 112 views
0

我遇到了UIImage内存大小问题。(iphone)UIImage占用多少内存?

  1. 当你有320个* 320分辨率的图像数据(PNG),当将图像加载到存储器,
    使用[UIImage的imageWithData:],将所得的UIImage将占用320 * 320 * 4?

  2. 屏幕大小(分辨率)会影响图像的内存使用情况吗?

  3. 下面的代码会占用myImage的两倍内存大小还是单个图像内存大小? (320 * 320 * 4)* 2 vs(320 * 320 * 4)?或者是其他东西?

    UIImage* myImage = [UIImage imageWithData:];  
    myImage = [myImage scaleToSize:]; 
    

    当scaleToSize作为

    - (UIImage*)scaleToSize:(CGSize)size 
    { 
        // Create a bitmap graphics context                        
    
    
        // This will also set it as the current context                                                        
        UIGraphicsBeginImageContext(size); 
    
        // Draw the scaled image in the current context                                                        
        [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; 
    
        // Create a new image from current context                                                         
        UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 
    
        // Pop the current context from the stack                                                         
        UIGraphicsEndImageContext(); 
    
        // Return our new scaled image                                                            
        return scaledImage; 
    } 
    

回答

0
显然

越大,图像越存储器将使用,同样适用于图像的量加载到内存中立刻被定义。

2

,如果你想测试特定的图像,而使用仪器运行在iPhone /模拟器应用程序检查内存分配

Run with the Allocations profile

确保你选择合适的目标。当你运行程序时,你会看到特定分配占用的内存空间。


当跑

你会看到窗口中分配的对象。就像这个,我附加了iTunes。

While running