我们如何在小型UIImageview上设置大型UIImage

时间:2013-02-15 09:39:18

标签: iphone

我使用尺寸为320X320的imagview来显示大图像(350 X 783)。

将大图像放入图像视图时,图像看起来被压缩,压缩的东西不像质量图像。

我的问题是,如何将大图像制作成与原始图像一样好的小图像?

3 个答案:

答案 0 :(得分:4)

您可以将图片视图设置为适当的内容模式,例如

        imageView.contentMode = UIViewContentModeScaleAspectFit

答案 1 :(得分:1)

-(UIImage*)scaleToSize:(CGSize)size {
    // Create a bitmap graphics context
    // This will also set it as the current context
    UIGraphicsBeginImageContext(size);
    // Draw the scaled image in the current context
    [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
    // Create a new image from current context
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    // Pop the current context from the stack
    UIGraphicsEndImageContext();
    // Return our new scaled image
    return scaledImage;
}

答案 2 :(得分:0)

你可以这样做,

    UIImage* sourceImage = "yourImage";
    CGSize newSize=CGSizeMake(80,80);
    UIGraphicsBeginImageContext( newSize );
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    yourImageView.image=newImage;