合并两个 UIImage

发布于 2024-10-06 09:03:59 字数 736 浏览 4 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感悟人生的甜 2024-10-13 09:03:59

该代码看起来是正确的(尽管我建议将其转换为使用创建的 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.

梦罢 2024-10-13 09:03:59

请注意,对于视网膜支持,您应该使用: 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文