FreeImage problems on Android (NDK)

365 views Asked by At

I tried to use FreeImage library to load PNG as a texture (from memory). That's the fragment of code:

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);

I'm using FILE with fopen to open file and then read stream to streamData object. File and stream is read correctly.

The result is: fileFormat = -1 and image is NULL.

I also tried to use FreeImage to load PNG file directly from disk using FreeImage_Load, but the result is the same - it returns NULL.

Has anybody faced similar problem? Can you suggest an alternative to FreeImage that can read data from memory?

1

There are 1 answers

1
Miki Franko On

try this code to load your image from memory:

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);
}