Iphone Sdk将2个图像重叠为一个

Iphone Sdk将2个图像重叠为一个,iphone,uiimage,Iphone,Uiimage,我有两张照片。。如何将它们重叠,以便获得1张图像?将图像2在图像1内的位置设置为X,Y 谢谢 为什么不创建一个UIView并将两个图像作为子视图放到其中 UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]]; UIView *imagesView = [[UIView alloc] initWithFrame:image.frame]; [imagesView ad

我有两张照片。。如何将它们重叠,以便获得1张图像?将图像2在图像1内的位置设置为X,Y


谢谢

为什么不创建一个UIView并将两个图像作为子视图放到其中

UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]];
UIView *imagesView = [[UIView alloc] initWithFrame:image.frame];
[imagesView addSubview:image];

UIImageView *imageToOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimagetooverlay.png"]];
[imageToOverlay setCenter:CGPointMake(10,10)];
[imagesView addSubview:imageToOverlay];

[self.view addSubview:imagesView];

为什么不创建一个UIView并将两个图像作为子视图放入其中

UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]];
UIView *imagesView = [[UIView alloc] initWithFrame:image.frame];
[imagesView addSubview:image];

UIImageView *imageToOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimagetooverlay.png"]];
[imageToOverlay setCenter:CGPointMake(10,10)];
[imagesView addSubview:imageToOverlay];

[self.view addSubview:imagesView];

扎帕西拉,你找到问题的答案了吗?你可以这样做:

#define imageWidth 40
#define imageHeight 60

UIImage *image1 = [UIImage imageNamed:@"firstimage.png"];
UIImage *image2 = [UIImage imageNamed: @"secondimage.png"];

CGSize itemSize = CGSizeMake(imageWidth, imageHeight);

UIGraphicsBeginImageContext(itemSize);

CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image1 drawInRect:imageRect];
[image2 drawInRect:imageRect];

UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage overlappedImage是一个新图像,其中包含初始图像重叠。老实说,我不知道这是否是达到这个效果的最佳方法,但我知道它确实有效


如果在此期间您找到了更有效的解决方案,请告诉我

扎帕西拉,你找到问题的答案了吗?你可以这样做:

#define imageWidth 40
#define imageHeight 60

UIImage *image1 = [UIImage imageNamed:@"firstimage.png"];
UIImage *image2 = [UIImage imageNamed: @"secondimage.png"];

CGSize itemSize = CGSizeMake(imageWidth, imageHeight);

UIGraphicsBeginImageContext(itemSize);

CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image1 drawInRect:imageRect];
[image2 drawInRect:imageRect];

UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage overlappedImage是一个新图像,其中包含初始图像重叠。老实说,我不知道这是否是达到这个效果的最佳方法,但我知道它确实有效


如果在此期间您找到了更有效的解决方案,请告诉我

谢谢你,托马斯。但这实际上是一个图像库,大概有20幅图像。。所以20个UIView并不能解决这个问题。另外,我需要一张后汉克斯·托马斯的缩略图。但这实际上是一个图像库,大概有20幅图像。。所以20个UIView并不能解决这个问题。再加上我需要一个缩略图