Imagens distorcidas

pessoal … estou usando esse metodo abaixo para baixar imagens da net de um diretorio …

mas as imagens salvas ficam distorcidas alguem sabe pq …


 public void  baixa(String urldown, String nome, String caminho) {
               
           String webFile = urldown;
         
           try {
           
             URL url = new URL(webFile);
             InputStream in = url.openStream();
             byte[] buf = new byte[1024];
           
             //Arquivo destino
             File fileDestiny = new File(caminho+nome);
             //Buffer de bytes
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             
             //grava arquivo no buffer 
             int x = 0;
             while((x = in.read()) != -1){
               baos.write(x);
             }
             in.close();
             //termina Gravação
             
             //Grava o arquivo manipulnado header se precisar ... ou seja se precisar hehe
             String fileContent = new String(baos.toByteArray());
             FileOutputStream o = new FileOutputStream(fileDestiny);
             o.write(fileContent.getBytes());
             o.flush();
             o.close(); 
             baos.close();
           
            //Finaliza gravação 
             
          }catch (Exception e) {
            System.err.println(e);
            e.printStackTrace();
        }
    }

Olá,

Ao escrever o arquivo, diria que seria melhor não fazer essa conversão para String. Pode até funcionar, mas pode criar problemas também. Procure escrever o byte array mesmo.

    ...
    o.write(baos.toByteArray());
    ....

[]s,
Sami

Digo: ao gravar.

Vou testar qualquer coisa posto ai … agradeço a ajuda …

Abraço velho !

Digo: ao gravar.[/quote]

Cara valeu mesmo … funcionou … era isso mesmo …

Se vc estivesse mais perto ai “finlandia” te pagava uns chops !!!

abraço

Beleza, que bom.

Hahah, estou longe mesmo :slight_smile:

[]s,
Sami