我想制作一个由其他UIImages制作的UIImage,大约10x10个其他UIImages,就像一个网格。有什么办法吗?
编辑1: 这是我到目前为止基于lnafziger链接的代码:
- (void)displayFullMap
{
NSInteger x, y;
UIGraphicsBeginImageContext(CGSizeMake(xMapLength * 64, yMapLength * 64));
CGRect rect = CGRectMake(0, 0, xMapLength * 64, yMapLength * 64);
UIImage *imageToAdd = [[UIImage alloc] init];
for (int i = 0; i < xMapLength; i++) {
for (int j = 0; j < yMapLength; j++) {
imageToAdd = some64x64image;
[imageToAdd drawInRect:rect];
rect.origin.x += 64;
}
rect.origin.x = 0;
rect.origin.y += 64;
}
UIImage *fullMapImage = [[UIImage alloc] init];
fullMapImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *fullMapImageView = [[UIImageView alloc] init];
[fullMapImageView setFrame:CGRectMake(0, 0, 360, 480)];
[fullMapImageView setImage:fullMapImage];
[self.view addSubview:fullMapImageView];
UIGraphicsEndImageContext();
}
但是,没有显示图像。我做错了什么?
答案 0 :(得分:0)
没有办法从另一个UIImage制作UIImage,但你可以将UIIMages添加到UIView,例如,并以网格模式排列它们。
否则,我建议使用Photoshop或其他方法制作图像,然后将其用于UIImageView。
答案 1 :(得分:0)
以下是展示如何合并多张图片的博客:
以下是该页面的代码(可以稍微清理一下,但它会向您展示技术):
@implementation LandscapeImage
- (void) createLandscapeImages
{
CGSize offScreenSize = CGSizeMake(2048, 1380);
UIGraphicsBeginImageContext(offScreenSize);
//Fetch First image and draw in rect
UIImage* imageLeft = [UIImage imageNamed:@"file1.png"];
CGRect rect = CGRectMake(0, 0, 1024, 1380);
[imageLeft drawInRect:rect];
[imageLeft release];
//Fetch second image and draw in rect
UIImage* imageRight = [UIImage imageNamed:@"file2.jpg"];
rect.origin.x += 1024;
[imageRight drawInRect:rect];
[imageRight release];
UIImage* imagez = UIGraphicsGetImageFromCurrentImageContext();// it will returns an image based on the contents of the current bitmap-based graphics context.
if (imageLeft && imageRight)
{
//Write code for save imagez in local cache
}
UIGraphicsEndImageContext();
}
@end