以固定大小显示图像
问题描述:
在我的应用程序中,图像从表格单元格中的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
感谢我将等待着你的回应....
答
我想我明白傻冒问...
你想要做的是调整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
你在该代码中的泄漏 cell.imageView.image = IMG; 应该是 cell.imageView.image = [img autorelease]; – 2010-07-05 06:53:15