首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在移动ios / android应用程序中是否可以使用不支持的非标准图像格式

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

Stack Overflow用户
提问于 2013-10-27 11:47:40
回答 1查看 480关注 0票数 0

我可以使用任何类型的图像格式,这些格式不像移动应用程序中的jpg那样受支持。可以向该文件发送请求,下载并保存该文件,并使用移动应用内部解码器将其解码为位图,并在屏幕上绘制该图片。所有这些都在移动应用客户端完成。有没有可能,如果是初学者,你能告诉我吗

EN

回答 1

Stack Overflow用户

发布于 2013-10-27 12:08:21

你可以使用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语言来处理其中的一些工作

下面是我所做的事情(再说一次,不能保证这适用于你的情况):

代码语言:javascript
复制
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);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19614421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档