我有一个资源(.png文件)显示图片框架(边框)。
此.png文件大小为100x100px,边框宽度为10px。目标c - UIImage调整大小问题
我的问题:
如何从这个图像创建另一个UIImage的,具有不同的尺寸,不毁了边框的宽度是多少?
问题:
当我尝试从原始图像与CGContextDrawImage
绘制新的图像我得到了新的尺寸新的形象,但我的边境比例废墟。
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newWidth, newHeight));
CGImageRef imageRef = //... the image
// Build a context that's the same dimensions as the new size
CGContextRef bitmap = CGBitmapContextCreate(NULL,
newRect.size.width,
newRect.size.height,
CGImageGetBitsPerComponent(imageRef),
0,
CGImageGetColorSpace(imageRef),
CGImageGetBitmapInfo(imageRef));
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(bitmap, kCGInterpolationHigh);
// Draw into the context; this scales the image
CGContextDrawImage(bitmap, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
// Clean up
CGContextRelease(bitmap);
CGImageRelease(newImageRef);
例如,当我试图创建一个图像尺寸800x100p,我得到的图像非常薄的顶部和底部边框。
我需要的是,边界将保持不变,宽度
*注意
使用resizableImageWithCapInsets:
不会帮助我,因为我需要一个新形象与新的大小保存在光盘上。
是否必须是资源?我确定有一种方法可以通过编程方式添加宽度和颜色的边框。我认为这不是您的选择(如果您想要自定义边框等),只需确保。 – Sti 2013-03-10 16:29:02
雅必须是.. – Eyal 2013-03-10 17:50:18