2012-12-06 142 views
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]; 

} 

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

任何帮助将是可观的。

+0

帧变化为图像计数在您的程序r使用恒定帧..? – NANNAV

+0

nope我不使用帧 –

+0

你使用self.view – NANNAV

回答

1

从每一个地方除了在合并下面的代码删除所有的代码。

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


} 
+0

感谢吨人!以及需要多一点支持....我希望我的'imageTwo'被拖拽但在这里我被卡住了,我只能做一个独特的图像是可移动的...我真的很感激,如果你唔帮我.. 。谢谢!! –

+0

如果您希望能够移动屏幕上已有的视图,则需要阅读有关名为“手势识别器”的一些信息。我假设,虽然你的要求是你有一桶图像,你应该能够拖拽第一个图像上的第二个图像。即使这样,你也需要阅读Gesture识别器。一旦完成,将所有子图像显示为视图,然后将每个图像拖放到顶部。让我知道你是否需要额外的帮助,但我相信你将能够弄清楚。 – Srikanth

+0

嗨@Srikanth我被困在一点,而使用触摸事件这里是问题** http://stackoverflow.com/questions/13761049/lower-the-cpu-usage-of-an-app** –