图像调整大小并在iphone中填充屏幕?

时间:2011-07-11 04:42:58

标签: iphone

我正在异步获取图像并在小框架(135,126)和大框架(280,325)上显示图像,图像可以是任意大小但是框架是固定的,必须要填充框架,现在我的问题是如何调整图像大小以填充这些尺寸的框架,但质量不应该降低,也像UIViewContentModeScaleAspectFill属性的图像方向做????

1 个答案:

答案 0 :(得分:1)

        UIImage *image = [actualImage you want to resize];
        UIImage *tempImage = nil;
        CGSize targetSize = CGSizeMake(196,110);
        UIGraphicsBeginImageContext(targetSize);

        CGRect thumbnailRect = CGRectMake(0, 0, 0, 0);
        thumbnailRect.origin = CGPointMake(0.0,0.0);
        thumbnailRect.size.width  = targetSize.width;
        thumbnailRect.size.height = targetSize.height;

        [image drawInRect:thumbnailRect];

        tempImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        You can use this tempImage , it will be resized Image

希望,这有帮助!