【发布时间】:2011-05-21 11:18:28
【问题描述】:
当我们调整图片的大小时(下载后存储到文档目录之前),通过以下代码:
-(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 release];正在释放一个不属于您的对象。
标签: iphone objective-c image iphone-sdk-3.0