合并两个UIImages [英] Merge two UIImages

查看:135
本文介绍了合并两个UIImages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有imageA(取自用户的iPhone相机)和imageB,一个带有傻边框(例如)的图像,有足够的透明alpha空间。

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.

什么我想要做的是合并这两个图像,将imageB放在imageA上,然后将它们保存为imageC用于其他工作。

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?

干杯

到目前为止我已经得到了这个

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

推荐答案

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

这篇关于合并两个UIImages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆