当我们使用imageWithContentsOfFile和imageNamed获得相同时,图像的大小是否不同

时间:2014-01-09 13:07:58

标签: ios iphone

我在PDF上绘制图像,但是当我使用 imageWithContentsOfFile 获取图像以在PDF上绘图时,PDF尺寸为133.6 mb但是当我使用 imageNamed 获取相同的图像时在PDF上绘制,然后PDF大小为568 KB。我无法理解为什么会出现这种差异?

    static int i = 0;
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.pdf", ++i]];
UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
for (int pageCounts = 1; pageCounts <= 15; pageCounts++) {
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 2000, 1960), nil);
    for (int imageCount = 1; imageCount < 9; imageCount++) {
        NSString *newFilePath = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%d",imageCount] ofType:@"png"];
        CGRect rectFImage1 = CGRectMake(15, 400*imageCount, 700, 400);
        UIImage *image1 = [UIImage imageWithContentsOfFile:newFilePath];


        [image1 drawInRect:rectFImage1];

        CGRect rectFImage2 = CGRectMake(800, 400*imageCount, 700, 400);
        UIImage *image2 = [UIImage imageWithContentsOfFile:newFilePath];
        [image2 drawInRect:rectFImage2];
    }
}
UIGraphicsEndPDFContext();



    static int i = 0;
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.pdf", ++i]];
UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
for (int pageCounts = 1; pageCounts <= 15; pageCounts++) {
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 2000, 1960), nil);
    for (int imageCount = 1; imageCount < 9; imageCount++) {
        CGRect rectFImage3 = CGRectMake(315, 400*imageCount, 700, 400);
        UIImage *image3 = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",imageCount]];
        [image3 drawInRect:rectFImage3];

        CGRect rectFImage4 = CGRectMake(1200, 400*imageCount, 700, 400);
        UIImage *image4 = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",imageCount]];
        [image4 drawInRect:rectFImage4];        }
}
UIGraphicsEndPDFContext();

0 个答案:

没有答案