2 starwar2012 starwar2012 于 2012.12.07 09:47 提问

将两张图片重叠后显示为新图片

想要实现两张图片重叠后显示为新突破,但是运行后模拟器什么也没显示

代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];

    image1 = [[UIImage alloc]init];

    image1 = [UIImage imageNamed:@"iphone.png"];

    imageA = [[UIImageView alloc]initWithImage:image1];


    [self merge];

}

-(void)merge
{
  CGSize size = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(size);

    CGPoint thumbPoint = CGPointMake(0,0);
    imageview.image = imageA.image;
    [imageA.image drawAtPoint:thumbPoint];

    imageB = [[UIImage alloc]init];

    imageB = [UIImage imageNamed:@"Favorites.png"];

    CGPoint starredPoint = CGPointMake(0, 0);
    [imageB drawAtPoint:starredPoint];

    UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageview.image = imageC;

    [self.view addSubview:imageview];

}

请高手指点,问题出在哪了?谢谢

1个回答

g989_1314125
g989_1314125   2012.12.07 13:42
已采纳

把你所有地方merge里面的代码换成下面的:

-(void)merge
{
    CGSize size = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(size);

    CGPoint point1 = CGPointMake(0,0);
   //两张图像必须有不同点,不然看不来是重叠
    CGPoint point2 = CGPointMake(100,100);

    UIImage *imageOne = [UIImage imageNamed:@"Image1.png"];
    [imageOne drawAtPoint:point1];



    UIImage *imageTwo = [UIImage imageNamed:@"Image2.png"];
  // 如果需要两张图片混搭,可以添加类似如下代码
  //  [imageTwo drawAtPoint:point2 blendMode:kCGBlendModeMultiply alpha:0.5];

    [imageTwo drawAtPoint:point2];


    UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(100,100,200,200)];
    iv.image=imageC;

    [self.view addSubview:iv];


}
starwar2012
starwar2012 谢谢!
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!