0

我想制作一个由其他 UIImage 制成的 UIImage,大约 10x10 个其他 UIImage,就像一个网格。有什么办法可以做到这一点?

编辑 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();
}

但是,没有显示图像。我究竟做错了什么?

4

2 回答 2

0

没有办法从另一个 UIImage 生成 UIImage,但是您可以将 UIIMages 添加到 UIView,例如,并以网格模式排列它们。

否则,我建议使用 Photoshop 或其他工具制作图像,然后将其用于 UIImageView。

于 2012-11-13T04:29:23.120 回答
0

这是一个展示如何合并多个图像的博客:

www.mindfiresolutions.com

这是该页面的代码(可以稍微清理一下,但它向您展示了技术):

@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
于 2012-11-13T05:43:33.470 回答