BitmapFactory.decodeByteArray sempre nulo (o que tem de errado?)

  • Respostas:1
Maycon Oliveira
  • Posts no fórum: 2

05/11/2015, 11:20:00 via Web

Olá pessoal.

O codigo abaixo esta bagunçado porque ja tentei todas as combinações possíveis para exibir a bendita imagem no ImageView.

A idéia é pegar uma imagem que eu gravei na memoria interna e exibir ela no ImageView.

Porem, o BitmapFactory.decodeByteArray não consegue puxar essa imagem recem gravada.

OBS: R.raw.teste é uma imagem válida que consigo abrir normalmente

OBS2: O while abaixo somente esta ali porque a idéia era colocar em um listview, mas pelo mesmo problema não consegui.

 try {
            InputStream inStream = getApplicationContext().getResources().openRawResource(
                    R.raw.teste);
            //  byte[] music = new byte[inStream.available()];
            FileOutputStream fos = openFileOutput("teste.png", MODE_PRIVATE);

            byte[] buffer = new byte[1024];
            int length = 0;
            try {
                while ((length = inStream.read(buffer)) > 0) {
                    fos.write(buffer, 0, length);
                }
                System.out.println(length);
            } catch (IOException ioe) {
                /* ignore */
            }

            inStream.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


        String[] files = getApplicationContext().fileList();
        for (String file : files) {
            if (file.endsWith("png")) {
                try {

                    FileInputStream fileInputStream = openFileInput(file);

                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    byte[] b = new byte[1024];
                    while (fileInputStream.available() > 0) {
                        bos.write(fileInputStream.read());
                    }

                    byte[] bytes = bos.toByteArray();

                    imgview.setImageBitmap(BitmapFactory.decodeByteArray(bytes, 0, bytes.length));

                    System.out.println(bytes.length);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

Alguma idéia?

Obrigado!

Responder
Maycon Oliveira
  • Posts no fórum: 2

05/11/2015, 17:47:58 via Web

To tentando pegar essa imagem de dentro da app somente para fins de teste. Será que ela é comprimida ou algo assim que evita a renderizacao?

Responder