合并两个 UIImage
我有 imageA (取自用户 iPhone 相机)和 imageB,这是一张带有愚蠢边框(例如)的图像,带有大量透明的 alpha 空间。
我想做的是合并这两个图像,将 imageB 放在 imageA 上,然后将它们保存为 imageC 以进行其他工作。
有办法做到这一点吗?
干杯
,到目前为止,
-(void)merge
{
CGSize size = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(size);
CGPoint thumbPoint = CGPointMake(0,0);
UIImage *imageA = imageView.image;
[imageA drawAtPoint:thumbPoint];
UIImage* starred = [UIImage imageNamed:@"imageB.png"];
CGPoint starredPoint = CGPointMake(0, 0);
[starred drawAtPoint:starredPoint];
UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView.image = imageC;
}
我看不到/不知道我在这里做错了什么
I have imageA (taken from the users iPhone camera) and imageB, an image with a silly boarder (for eg) with plenty of transparent alpha space.
What I would like to to do is to merge these two images, laying imageB over imageA, and then saving them as imageC for other work.
Is there a way to do this?
Cheers
I've got this so far
-(void)merge
{
CGSize size = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(size);
CGPoint thumbPoint = CGPointMake(0,0);
UIImage *imageA = imageView.image;
[imageA drawAtPoint:thumbPoint];
UIImage* starred = [UIImage imageNamed:@"imageB.png"];
CGPoint starredPoint = CGPointMake(0, 0);
[starred drawAtPoint:starredPoint];
UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView.image = imageC;
}
I can't see/dont know what I'm doing wrong here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该代码看起来是正确的(尽管我建议将其转换为使用创建的 CGBitmapContext 用于线程安全),但是
imageB
应该是 JPEG 吗? JPEG 不支持透明度,因此,为了使混合正常工作,它实际上应该是 PNG。That code looks correct (though I would recommend converting it to use a created CGBitmapContext for thread-safety), but is
imageB
supposed to be a JPEG? JPEGs don't support transparency, so, in order for the blending to work, it should really be a PNG.请注意,对于视网膜支持,您应该使用: UIGraphicsBeginImageContextWithOptions(size, YES, 0); // 0 表示让 iOS 为您处理缩放
Note that for retina support you should use:
UIGraphicsBeginImageContextWithOptions(size, YES, 0); // 0 means let iOS deal with scale for you