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

标签 android ios mobile image-processing mobile-application

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

最佳答案

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

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

如果在您的应用摄取图像之前完全有可能将您的图像转换成这种格式,您应该尝试将其作为 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);
}

关于android - 非标准不支持的图像格式可以在移动 ios/android 应用程序中使用吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19614421/

相关文章:

java - 计算器应用程序在 android.support.v4.view.ViewPager 处因 java.lang.NullPointerException 崩溃

android - 应用程序崩溃后相机未释放

android - 如何在圆形 ImageView 周围绘制边框?

java - Android 和 ios 中的单词库

java - 你如何在Android中获得手机的MCC和MNC?

android - 是否可以仅更新移动平台上应用程序的某些部分?

mobile - Rhodes v/s 钛合金

android - 如何获取 android.widget.ImageView 的宽度和高度?

objective-c - 在 UISearchBar 中搜索时自动完成

iphone - 使用 outlet Collection 检查是否所有分段控件都被选中