2010-07-05 116 views
0

在我的應用程序中,圖像從表格單元格中的rss源加載。他們是不同的大小,我怎麼能修復他們到一定的大小。我的代碼是以固定大小顯示圖像

int blogEntryIndex1 = [indexPath indexAtPosition: [indexPath length] -1]; 

imgstring=[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey: @"image"]; 
NSURL *url = [NSURL URLWithString:imgstring]; 


NSData *data = [NSData dataWithContentsOfURL:url]; 

UIImage *img = [[UIImage alloc] initWithData:data]; 
cell.imageView.image=img; 

您可以查看我的應用程序屏幕截圖click here

感謝我將等待着你的迴應....

+0

你在該代碼中的泄漏 cell.imageView.image = IMG; 應該是 cell.imageView.image = [img autorelease]; – 2010-07-05 06:53:15

回答

3

我想我明白傻冒問...

你想要做的是調整UIImages的大小。

UIImage* resizeImageToSize(UIImage* image, CGSize size) 
{ 
    UIGraphicsBeginImageContext(size); 

    CGContextRef ctx = UIGraphicsGetCurrentContext(); 

    //Account for flipped coordspace 
    CGContextTranslateCTM(ctx, 0.0, size.height); 
    CGContextScaleCTM(ctx, 1.0, -1.0); 

    CGContextDrawImage(ctx,CGRectMake(0.0f, 0.0f, size.width, size.height), image.CGImage); 

    UIImage* scaled = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 
    return scaled; 
} 
+1

我給你的是一個c風格的函數。這聽起來像是你將它粘貼到另一個函數的主體中。 – 2010-07-05 07:28:14

+0

你爲什麼一直叫我親愛的......以及一個複選標記如何 – 2010-07-05 07:42:57

相關問題