【问题标题】:Can non-standard unsupported image formats be used in mobile ios / android apps非标准不支持的图像格式可以在移动ios / android应用程序中使用吗
【发布时间】:2013-10-27 03:47:39
【问题描述】:

我可以在移动应用程序中使用与 jpg 不同的任何类型的图像格式吗? 可以向该文件发送请求,下载并保存它,并使用移动应用程序内的解码器解码为位图并在屏幕上绘制图片。全部在移动应用客户端完成。 有没有可能,如果是初学者的起点可以告诉我

【问题讨论】:

    标签: android ios mobile image-processing mobile-application


    【解决方案1】:

    你可以see the supported image formats for UIImage in table 1 here

    .tiff .tif .jpg .jpeg .gif .png .bmp .ico .cur .xbm 都可以使用 UIImage 的本机方法轻松合并。

    如果有可能在您的应用摄取图像之前将图像转换为这种格式,您应该尝试这样做,因为 imageWithContentsOfFile: 或 imageWithData: 方法对您来说比编写工作要少得多并使用自定义类来解析和转换另一种格式。

    您是否有必须使用的特定格式不能先转换为 .tif .jpg .bmp 或 .png ?

    更新以响应 OP

    可能有一些项目做了类似的事情,但我可以为您提供的唯一相关经验来自一个机器视觉项目,我将原始像素数据处理为原始数据,并将其加载回 CGImageRef 以供使用界面。

    您可能会直接分配内存并直接使用 C 语言处理其中的一些内容

    这是我所做的一个尝试(同样,不能保证这将适用于您的情况):

    size_t bitMatrixSize = (height-2*k_kernelPixelRadius) * (width-2*k_kernelPixelRadius);
    unsigned char *bitMatrix = malloc(bitMatrixSize); //back to int, so only 1 byte per pixel needed
    //other methods manipulated the data stored in this unsigned char, then passed it to the following method
    
    +(CGImageRef)newImageFromBitMatrix:(unsigned char*)bitMatrix originalImagePixelHeight:(int)origHeight originalImagePixelWidth:(int)origWidth{
    
    int pixelsInBitMatrix = (origHeight - (2 * k_kernelPixelRadius)) * (origWidth - (2 * k_kernelPixelRadius));
    unsigned char *rawData = malloc(pixelsInBitMatrix * 4); //1 byte per char, 4 bytes per pixel (RGBA)
    int outputColor = 0;
    int byteIndex = 0;
    
    for (int i = 0; i < pixelsInBitMatrix; i++) {
        //outputColor = (bitMatrix[i] == 1) ? 255 : 0;    //This is the shorter form, the undefined grey was included for debugging. Remove it later
        if (bitMatrix[i] == 1) {
            outputColor = 255;
        }
        else if (bitMatrix[i] == 0) {
            outputColor = 0;
        }
        else {
            outputColor = 150;
        }
    
        rawData[byteIndex] = outputColor;
        rawData[byteIndex + 1] = outputColor;
        rawData[byteIndex + 2] = outputColor;
        rawData[byteIndex + 3] = 255; //alpha channel
    
        byteIndex += 4;
    }
    
    CGContextRef ctx = NULL; 
    CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB();
    size_t contextWidth = origWidth - (2 * k_kernelPixelRadius);
    size_t contextHeight = origHeight - (2 * k_kernelPixelRadius);
    size_t bytesPerRow = 4 * contextWidth;
    
    ctx = CGBitmapContextCreate(rawData,  
                                contextWidth,  
                                contextHeight,  
                                8,  
                                bytesPerRow,  
                                deviceRGB,  
                                kCGImageAlphaPremultipliedLast ); 
    
    CGImageRef thresholdImage = CGBitmapContextCreateImage (ctx);  
    CGColorSpaceRelease(deviceRGB);
    CGContextRelease(ctx);  
    free(rawData);
    
    return thresholdImage;
    free(bitMatrix);
    }
    

    【讨论】:

    • 感谢 :) 对于某些成像应用程序,它可能会成为一种定制的图像格式,因此它可能不会转换为现有形式。所以它可以做仪式吗? :) 我也发现了这个stackoverflow.com/questions/4874896/…,但它没有清楚地提到如何。你知道任何可以使用的方法/类,我可以尝试阅读,这将有助于位图映射,然后在屏幕上插入和绘制图片
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多