Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch “我怎么能?”;上传“;将原始图像文件发送到iOS模拟器?_Cocoa Touch_Ios_Ios Simulator - Fatal编程技术网

Cocoa touch “我怎么能?”;上传“;将原始图像文件发送到iOS模拟器?

Cocoa touch “我怎么能?”;上传“;将原始图像文件发送到iOS模拟器?,cocoa-touch,ios,ios-simulator,Cocoa Touch,Ios,Ios Simulator,如何将原始图像文件“上传”到iOS模拟器,使其在AssetLibrary框架中显示,就像通过摄像头连接套件将原始图像从摄像头复制到iPad一样 (我知道如何在iOS模拟器中存储普通的JPEG和PNG图像。这不是问题。)我对原始数据不是很熟悉,但我能够将PNG图像转换为原始数据,然后再转换回图像。以下是我用来转换为图像的代码: - (UIImage *) convertBitmapRGBA8ToUIImage:(unsigned char *) buffer

如何将原始图像文件“上传”到iOS模拟器,使其在AssetLibrary框架中显示,就像通过摄像头连接套件将原始图像从摄像头复制到iPad一样


(我知道如何在iOS模拟器中存储普通的JPEG和PNG图像。这不是问题。)

我对原始数据不是很熟悉,但我能够将PNG图像转换为原始数据,然后再转换回图像。以下是我用来转换为图像的代码:

- (UIImage *) convertBitmapRGBA8ToUIImage:(unsigned char *) buffer 
                                withWidth:(int) width
                               withHeight:(int) height {


    size_t bufferLength = width * height * 4;
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, bufferLength, NULL);
    size_t bitsPerComponent = 8;
    size_t bitsPerPixel = 32;
    size_t bytesPerRow = 4 * width;

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    if(colorSpaceRef == NULL) {
        NSLog(@"Error allocating color space");
        CGDataProviderRelease(provider);
        return nil;
    }

    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; 
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

    CGImageRef iref = CGImageCreate(width, 
                                    height, 
                                    bitsPerComponent, 
                                    bitsPerPixel, 
                                    bytesPerRow, 
                                    colorSpaceRef, 
                                    bitmapInfo, 
                                    provider,   // data provider
                                    NULL,       // decode
                                    YES,            // should interpolate
                                    renderingIntent);

    uint32_t* pixels = (uint32_t*)malloc(bufferLength);

    if(pixels == NULL) {
        NSLog(@"Error: Memory not allocated for bitmap");
        CGDataProviderRelease(provider);
        CGColorSpaceRelease(colorSpaceRef);
        CGImageRelease(iref);       
        return nil;
    }

    CGContextRef context = CGBitmapContextCreate(pixels, 
                                                 width, 
                                                 height, 
                                                 bitsPerComponent, 
                                                 bytesPerRow, 
                                                 colorSpaceRef, 
                                                 kCGImageAlphaPremultipliedLast); 

    if(context == NULL) {
        NSLog(@"Error context not created");
        free(pixels);
    }

    UIImage *image = nil;
    if(context) {

        CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), iref);

        CGImageRef imageRef = CGBitmapContextCreateImage(context);

        // Support both iPad 3.2 and iPhone 4 Retina displays with the correct scale
        if([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) {
            float scale = [[UIScreen mainScreen] scale];
            image = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];
        } else {
            image = [UIImage imageWithCGImage:imageRef];
        }

        CGImageRelease(imageRef);   
        CGContextRelease(context);  
    }

    CGColorSpaceRelease(colorSpaceRef);
    CGImageRelease(iref);
    CGDataProviderRelease(provider);

    if(pixels) {
        free(pixels);
    }   
    return image;
}
我真的记不起来源了,但它对我有用

您是否能够使用代码加载原始图像?如果是,只需将数据传递到上述函数(您还需要正确转换图像的宽度和高度)。

只需使用

writeImageDataToSavedPhotosAlbum:元数据:completionBlock:


将原始文件的图像数据写入已保存的相册。iOS支持多种原始格式(佳能和尼康绝对受支持)。当您将原始文件添加到库中时,AssetLibrary会自动为您的原始文件创建jpeg和预览。

对不起,您误解了“原始图像”在本上下文中的含义。这里的“RAW”是指一类特定于相机的RAW文件格式,如.cr2(佳能)和.nef(尼康),其中包含直接来自相机传感器的每像素数据(参见维基百科的“彩色滤光片阵列”),以及exporsure元数据等,编码方式为非公开文档(但在大多数情况下是重新设计并广为人知的,谷歌的“dcraw”)。有些这样的格式甚至是部分加密的。您会想到“原始”未打包的每通道8位RGB数据,这是完全不同的事情。