,我使用的調整大小代碼圖像邊緣1000px最多是這樣的:
const int maxPhotoWidthOrHeight = 1000;
- (UIImage*)resizeImageWithImage:(UIImage*)image
{
CGFloat oldWidth = image.size.width;
CGFloat oldHeight = image.size.height;
NSLog(@"Old width %f , Old Height : %f ",oldWidth,oldHeight);
if (oldHeight > maxPhotoWidthOrHeight || oldWidth > maxPhotoWidthOrHeight) {//resize if necessary
CGFloat newHeight;
CGFloat newWidth;
if (oldHeight > oldWidth) {
newHeight = maxPhotoWidthOrHeight;
newWidth = oldWidth * (newHeight/oldHeight);
}
else{
newWidth = maxPhotoWidthOrHeight;
newHeight = oldHeight * (newWidth/oldWidth);
}
CGSize newSize = CGSizeMake(newWidth, newHeight);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"New width %f , New Height : %f ",newImage.size.width,newImage.size.height);
return newImage;
}
else{//do not resize because both edges are less than 1000px
return image;
}
}
你就不能讓你的屏幕比例寬度/高度,然後應用,爲你的形象,你必須顯示? – 2012-03-05 14:26:46