Ios iPad上最快的图像格式是什么?

Ios iPad上最快的图像格式是什么?,ios,uiimage,cgimage,Ios,Uiimage,Cgimage,假设如下: 您可以在ipad应用程序中从互联网下载图像 您可以按任何方式对图像进行后处理,下载数据时所需的时间并不重要。设备上的实际表示也不重要。 您可以按照任何方式为该映像编写加载代码,只要生成UIImage即可 问题是:在iPad上存储图像的最佳格式是什么,以便加载图像所需的时间尽可能短?CG…上下文位图内存的某种原始转储?与此同时,我想我已经弄明白了: 要保存UIImage,我在类别中添加了此方法: typedef struct { int width; int heigh

假设如下:

您可以在ipad应用程序中从互联网下载图像 您可以按任何方式对图像进行后处理,下载数据时所需的时间并不重要。设备上的实际表示也不重要。 您可以按照任何方式为该映像编写加载代码,只要生成UIImage即可
问题是:在iPad上存储图像的最佳格式是什么,以便加载图像所需的时间尽可能短?CG…上下文位图内存的某种原始转储?

与此同时,我想我已经弄明白了:

要保存UIImage,我在类别中添加了此方法:

typedef struct
{
    int width;
    int height;
    int scale;

    int bitsPerComponent;
    int bitsPerPixel;
    int bytesPerRow;
    CGBitmapInfo bitmapInfo;
} ImageInfo;

-(void)saveOptimizedRepresentation:(NSString *)outputPath
{
    NSData * pixelData = (__bridge_transfer NSData *)CGDataProviderCopyData(CGImageGetDataProvider(self.CGImage));
    CGSize size;
    size.width = CGImageGetWidth(self.CGImage);
    size.height = CGImageGetHeight(self.CGImage);
    int bitsPerComponent = CGImageGetBitsPerComponent(self.CGImage);
    int bitsPerPixel = CGImageGetBitsPerPixel(self.CGImage);
    int bytesPerRow = CGImageGetBytesPerRow(self.CGImage);
    int scale = self.scale;
    CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(self.CGImage);

    ImageInfo info;
    info.width = size.width;
    info.height = size.height;
    info.bitsPerComponent = bitsPerComponent;
    info.bitsPerPixel = bitsPerPixel;
    info.bytesPerRow = bytesPerRow;
    info.bitmapInfo = bitmapInfo;
    info.scale = scale;

    //kCGColorSpaceGenericRGB
    NSMutableData * fileData = [NSMutableData new];

    [fileData appendBytes:&info length:sizeof(info)];
    [fileData appendData:pixelData];

    [fileData writeToFile:outputPath atomically:YES];
}
要加载它,我添加了以下内容:

+(UIImage *)loadOptimizedRepresentation:(NSString *)inputPath
{
    FILE * f = fopen([inputPath cStringUsingEncoding:NSASCIIStringEncoding],"rb");
    if (!f) return nil;

    fseek(f, 0, SEEK_END);
    int length = ftell(f) - sizeof(ImageInfo);
    fseek(f, 0, SEEK_SET);

    ImageInfo info;
    fread(&info, 1, sizeof(ImageInfo), f);

    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();

    CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
                                                       info.width,
                                                       info.height,
                                                       info.bitsPerComponent,
                                                       info.bytesPerRow,
                                                       cs,
                                                       info.bitmapInfo
                                                       );

    void * targetData = CGBitmapContextGetData(bitmapContext);
    fread(targetData,1,length,f);

    fclose(f);

    CGImageRef decompressedImageRef = CGBitmapContextCreateImage(bitmapContext);

    UIImage * result = [UIImage imageWithCGImage:decompressedImageRef scale:info.scale orientation:UIImageOrientationUp];

    CGContextRelease(bitmapContext);
    CGImageRelease(decompressedImageRef);
    CGColorSpaceRelease(cs);

    return result;
}

因此,您将映像存储在文件系统上的一个文件中。您能否详细介绍一下与仅在文件系统中存储JPG或PNG相比所节省的成本。甚至可以与保存在数据库中进行比较?