可以在移动ios / android应用程序中使用非标准不受支持的图像格式

时间:2013-10-27 03:47:40

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

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

1 个答案:

答案 0 :(得分: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);
}