0

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?

rafalczuj
  • 51
  • 1
  • 5
  • Have you solved it? I have similiar problem here: http://stackoverflow.com/questions/42120978/freeimage-getfiletype-not-working-in-android-ndk – user7428910 Feb 08 '17 at 20:35
  • @user7428910 Actually we changed library for processing png. Couldn't make it work with FreeImage – rafalczuj Jun 06 '17 at 07:10

1 Answers1

0

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);
}
Miki Franko
  • 687
  • 3
  • 7