【问题标题】:stretch a image to a larger size without disturbing the pixels in iPhone在不影响 iPhone 像素的情况下将图像拉伸到更大的尺寸
【发布时间】:2011-03-25 05:27:42
【问题描述】:

我有一个视图,它有 3 个子视图,并且所有三个子视图在 uiscrollviews 中都有 uimageviews。所以图像视图可以滚动或缩放。图片很大。
现在视图的总尺寸为 480X320,但我想捕获更大尺寸的屏幕,例如 960X640。但是当我尝试这样做时,图像被拉伸,像素受到干扰。

有没有办法拉伸尺寸大但以小框显示的图像?

谢谢 潘卡伊

【问题讨论】:

  • excellent blog post 为您提供了正确调整图像大小的好技巧。希望对您有所帮助。

标签: iphone uiview uiimageview


【解决方案1】:

试试这个对我有用的代码。

-(UIImage *)resizeImage:(UIImage *)图像宽度:(int)width 高度:(int)height {

CGImageRef imageRef = [image CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);

//if (alphaInfo == kCGImageAlphaNone)
    alphaInfo = kCGImageAlphaNoneSkipLast;

CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), 4 * width, CGImageGetColorSpace(imageRef), alphaInfo);
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];

CGContextRelease(bitmap);
CGImageRelease(ref);

return result;  

}

【讨论】:

    猜你喜欢
    • 2012-08-22
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2017-10-17
    • 1970-01-01
    相关资源
    最近更新 更多