我尝试使用FreeImage库将PNG作为纹理加载(从内存中)。这是代码的片段:
FIMEMORY *fiStream = FreeImage_OpenMemory(streamData, size);
FREE_IMAGE_FORMAT fileFormat = FreeImage_GetFileTypeFromMemory(fiStream, 0);
FIBITMAP *image = FreeImage_LoadFromMemory(fileFormat, fiStream, 0);
int bitsPerPixel = FreeImage_GetBPP(image);
width = (int)FreeImage_GetWidth(image);
height = (int)FreeImage_GetHeight(image);我使用带有fopen的文件打开文件,然后将流读取到streamData对象。正确读取文件和流。
结果是: fileFormat = -1,而图像为NULL。
我还尝试使用FreeImage直接使用FreeImage_Load从磁盘加载PNG文件,但结果是相同的--它返回NULL。
有没有人遇到过类似的问题?您能建议一种可以从内存中读取数据的FreeImage的替代方案吗?
发布于 2014-11-26 08:51:47
尝试使用以下代码从内存中加载图像:
File file = new File("/sdcard/Images/image1.jpg");
if(file.exists()){
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
ImageView image = (ImageView) findViewById(R.id.imageview);
image.setImageBitmap(bitmap);
}https://stackoverflow.com/questions/27144659
复制相似问题