tintim_22 Posted October 19, 2012 at 05:10 PM Report #479774 Posted October 19, 2012 at 05:10 PM Boas, preciso de uma pequena ajuda do forum, como mostrar imagens que tenho no SDcard via ListView? Obg.
David Carpinteiro Posted October 20, 2012 at 09:39 PM Report #479886 Posted October 20, 2012 at 09:39 PM Boas, Vê se este exemplo te ajuda http://mihaifonoage.blogspot.pt/2009/09/displaying-images-from-sd-card-in.html. Espero que ajude. David
tintim_22 Posted October 23, 2012 at 03:24 PM Author Report #480095 Posted October 23, 2012 at 03:24 PM (edited) Boas, Vê se este exemplo te ajuda http://mihaifonoage.blogspot.pt/2009/09/displaying-images-from-sd-card-in.html. Espero que ajude. ando mm embrulhado com as multi soluções que já procurei, já perdi tempo com isto e não estou a dar volta à solução, tenho um file .gif (que não é animado) no sdcard, a path está numa table via sqlite, a path está correcta, o meu code é: File f = new File(path); ImageView iv = (ImageView) v.findViewById(R.id.pic); iv.setImageDrawable(Drawable.createFromPath(f.getAbsolutePath())); e dá-me sempre o mesmo erro: skimagedecoder::factory returned null mas dá null pq? e qual a solução para estes casos? =( Edited October 23, 2012 at 03:38 PM by KTachyon Tags de código
KTachyon Posted October 23, 2012 at 03:37 PM Report #480100 Posted October 23, 2012 at 03:37 PM Em principio o Drawable não sabe o que é um gif. Deves precisar de instanciar como BitmapDrawable. De qualquer forma é mais simples utilizares um BitmapFactory para criar o bitmap da imagem e a colocares na ImageView: File f = new File(path); ImageView iv = (ImageView) v.findViewById(R.id.pic); Bitmap bmImg = BitmapFactory.decodeFile(f.getPath()); iv.setImageBitmap(bmImg); “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
tintim_22 Posted October 23, 2012 at 03:43 PM Author Report #480102 Posted October 23, 2012 at 03:43 PM Em principio o Drawable não sabe o que é um gif. Deves precisar de instanciar como BitmapDrawable. De qualquer forma é mais simples utilizares um BitmapFactory para criar o bitmap da imagem e a colocares na ImageView: File f = new File(path); ImageView iv = (ImageView) v.findViewById(R.id.pic); Bitmap bmImg = BitmapFactory.decodeFile(f.getPath()); iv.setImageBitmap(bmImg); =( same error...!!! começo a deduzir que não vou conseguir ler este tipo de file...
KTachyon Posted October 23, 2012 at 04:03 PM Report #480110 Posted October 23, 2012 at 04:03 PM O que tens no path? “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
tintim_22 Posted October 23, 2012 at 04:22 PM Author Report #480114 Posted October 23, 2012 at 04:22 PM O que tens no path? no path tenho /mnt/sdcard/IMGXXX.gif
KTachyon Posted October 23, 2012 at 04:24 PM Report #480115 Posted October 23, 2012 at 04:24 PM Mas escreveste isso manualmente? Faz assim: String sd_path = Environment.getExternalStorageDirectory().toString(); file = new File(sd_path, "path_do_ficheiro_no_sd"); Precisas de importar o Environment, se não estiveres já a fazê-lo: import android.os.Environment; “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
tintim_22 Posted October 23, 2012 at 04:39 PM Author Report #480116 Posted October 23, 2012 at 04:39 PM Mas escreveste isso manualmente? Faz assim: String sd_path = Environment.getExternalStorageDirectory().toString(); file = new File(sd_path, "path_do_ficheiro_no_sd"); Precisas de importar o Environment, se não estiveres já a fazê-lo: import android.os.Environment; o meu logcat mostra aquela path (atraves do f.getAbsolutePath()), vou com o emulador e os files estão naquela path, acrescentando a tua linha de code, fico com /mnt/sdcard/mnt/sdcard/IMGXXX.gif o que esta errado eu tou a fazer tudo bem e não estou a perceber o porque de não estar a funcionar.... errrrrrr!
KTachyon Posted October 23, 2012 at 04:46 PM Report #480118 Posted October 23, 2012 at 04:46 PM Sim, mas tu não queres acrescentar o que tens, queres só dizer onde está a imagem. O path do SD pode variar, pelo que deves sempre obter esse path através da instrução Environment.getExternalStorageDirectory(). O resto é o caminho para a tua imagem, que no teu caso é só o nome do ficheiro. De qualquer forma, o erro que indicaste acontece quando o ficheiro que estás a ler não é uma imagem válida. És tu que o estás a gravar para o SD, certo? Como estás a fazer isso? E, de certeza que quando o fazes estás a gravar uma imagem? “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
tintim_22 Posted October 23, 2012 at 04:58 PM Author Report #480120 Posted October 23, 2012 at 04:58 PM Sim, mas tu não queres acrescentar o que tens, queres só dizer onde está a imagem. O path do SD pode variar, pelo que deves sempre obter esse path através da instrução Environment.getExternalStorageDirectory(). O resto é o caminho para a tua imagem, que no teu caso é só o nome do ficheiro. De qualquer forma, o erro que indicaste acontece quando o ficheiro que estás a ler não é uma imagem válida. És tu que o estás a gravar para o SD, certo? Como estás a fazer isso? E, de certeza que quando o fazes estás a gravar uma imagem? via json, processo, meto a path local no sql e creio eu que faço o download da img para o meu lado (o ficheiro é criado e guardado na path indicada)... testo a path que vem no json no browser e realmente vejo a img... =(
KTachyon Posted October 23, 2012 at 05:10 PM Report #480122 Posted October 23, 2012 at 05:10 PM (edited) Sim, mas veres a imagem no browser é diferente daquilo que estás a gravar no SD. Tu recebes um JSON que tem o endereço web onde a imagem se encontra, depois tens que a descarregar e gravar num ficheiro no teu SD. Coisa que será qualquer coisa como: String sd_path = Environment.getExternalStorageDirectory().toString(); File file = new File(sd_path, imageName); // imageName == nome da tua imagem Bitmap bmImg = null; URL myFileUrl = null; try { myFileUrl = new URL(fileUrl); // fileUrl == url para a tua imagem } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection)myFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is); // se a imagem for descodificada, é garantido que estás a obter uma imagem if (bmImg != null) { // Gravar a imagem no SD try { FileOutputStream out = new FileOutputStream(file); image.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } } else { // A imagem não é válida. } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Edited October 23, 2012 at 05:11 PM by KTachyon “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
tintim_22 Posted October 24, 2012 at 02:10 PM Author Report #480265 Posted October 24, 2012 at 02:10 PM Sim, mas veres a imagem no browser é diferente daquilo que estás a gravar no SD. Tu recebes um JSON que tem o endereço web onde a imagem se encontra, depois tens que a descarregar e gravar num ficheiro no teu SD. Coisa que será qualquer coisa como: bmImg = BitmapFactory.decodeStream(is); // se a imagem for descodificada, é garantido que estás a obter uma imagem if (bmImg != null) { // Gravar a imagem no SD try { ... image.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } } else { // A imagem não é válida. } } tudo igual menos este pedaço de code... que fez toda a diferença, já funciona, obg!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now