如何调整来自Xml Feed的图像的大小

时间:2010-07-07 15:06:18

标签: objective-c cocoa-touch uitableview iphone

我从Xml提要中获取图像,然后在表格单元格中显示它我想要做的是将图像调整为我的代码的最小大小为5kb。

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 autorelease];

提前致谢。

1 个答案:

答案 0 :(得分:1)

如果有帮助的话,试试这个:

CGSize itemSize = CGSizeMake(kAppIconWidth, kAppIconHeight);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
self.cell.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();