English 中文(简体)
重新缩放后获取图像数据 。
原标题:Get image data for resizableImageWithCapInsets: after being resized

我有一个图纸, 我用它作为另一个图像的图像遮罩。 这两张图纸的圆角都以可变缩放图像与 CapInset 保存 : 。 图像( 不是面具) 正在自动缩放, 因为它是 UI ProgressView 的进度图像 。

我面临的问题是,如果我使用 CGIMageMaskCreate 来制作一个面具, 简单给它以UIProgresView 宽度, 面具图像正在被拉伸( 也就是说, 它不保存盖子 ) 。

我所要做的是创建一个新的带有可变盖子的 UIIMage, 手动调整图像大小( 也许通过将图像放入 UIIMageView ), 获取已调整版面罩图像的数据表示, 然后用该数据创建新图像, 并使用该图像作为面具 。 不过, 似乎即使我用图像创建了 UIIMageView, 并适当设置了 UIIMageView 框架, 将图像从视图中获取回原图像 。

是否有办法取得可变化图像与CapInsets的结果:图像不会被实际拖入 UI 吗?

问题回答

我会尝试在 CGContext 中逐块绘制图像块, 以便您访问数据提供者, 或者通过创建 UIImaage 提取 NSData 。

- (UIImage*) drawImage:(UIImage *)image
                atSize:(CGSize) size
{
    UIGraphicsBeginImageContext(size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];

    CGImageRef cgImage = CGBitmapContextCreateImage(context);
    UIImage *outImage = [UIImage imageWithCGImage:cgImage];

    CGImageRelease(cgImage);
    UIGraphicsEndImageContext();

    return outImage;
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签