当我们调整大小的图像(下载之后并存储在文件目录之前),通过下面的代码:薄WHITELINE是被添加时调整图像大小
-(UIImage *)resizeImage:(UIImage *)image withSize:(CGSize)newSize
{
float actualHeight = image.size.height;
float actualWidth = image.size.width;
float imgRatio = actualWidth/actualHeight;
float maxRatio = newSize.width/newSize.height;
if(imgRatio!=maxRatio){
if(imgRatio < maxRatio){
imgRatio = newSize.width/actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = newSize.width;
}
else{
imgRatio = newSize.height/actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = newSize.height;
}
}
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
UIGraphicsBeginImageContext(rect.size);
[image drawInRect:rect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//[resizedImage release];
return [resizedImage autorelease];
}
此产生与重新尺寸图像细的白线添加到它的方向(如果图像是横向白线添加到它的底部,如果图像是纵向白线添加到它的右手)。
请说清楚,如何摆脱那条白线?
谢谢。
[resizedImage发布];正在释放一个你不拥有的物体。 – MattyG 2011-09-13 05:29:40