合并多个图像以获得单个图像

时间:2012-03-13 07:34:40

标签: image ipad image-processing ios5

我要捕捉UIView的内容。有很多方法可以捕获内容。
问题是,如果视图的大小变得太大,应用程序会崩溃,因为它需要大量的内存。
所以有可能合并单个文件中的原始图像数据(执行逐字节操作)并从中生成图像?

1 个答案:

答案 0 :(得分:0)

`enter code here`Merging two images to create one single image file

Suppose we have two images with name file1.png and file2.png The code below merges two images.

@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