0

我正在尝试重叠两个本地图像并尝试在第三个图像中显示重叠的一个。我正在使用此代码,但模拟器什么也没显示。

- (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];

}

我不知道/不知道我在哪里犯错。

任何帮助都是不言而喻的。

4

2 回答 2

1

从 Merge 中的以下代码除外的所有位置删除所有代码。

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

    CGPoint point1 = CGPointMake(0,0);
   // The second point has to be some where different than the first point, other wise, the second image will be above the first image, and you wont even know that the two images are there.
    CGPoint point2 = CGPointMake(100,100);

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



    UIImage *imageTwo = [UIImage imageNamed:@"Image2.png"];
  // If you want the above image to have some blending, then you can do some thing like below. 
  //  [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];


}
于 2012-12-06T12:41:37.877 回答
0

这是一个通用的“合并”函数,写为 UIImage 类别......允许图像叠加/底图。

http://saveme-dot-txt.blogspot.com/2011/06/merge-image-function.html

于 2012-12-06T12:36:47.737 回答