android downloaded images are not in correct format -
i'm downloading images webservice using below code , works fine after downloaded , copied sd card, unknown file types although have .jpg @ end , application still can load them imageviews can't open of downloaded images via device's gallery file manager. idea?
here's how download , save images:
public void downloadimage(string url, string filename) { try { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder() .permitall().build(); strictmode.setthreadpolicy(policy); string[] filenamesplit = filename.split("\\."); string filenamemobile = filenamesplit[0] + "-mob." + filenamesplit[1]; url urlconnection = new url(url); urlconnection connection = urlconnection.openconnection(); inputstream in = connection.getinputstream(); file outfile = new file(file.getpath() + "/" + filenamemobile); outputstream out = new fileoutputstream(outfile); copyfile(in, out); out.close(); in.close(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } example file name in directory browsed file manager:
_58df8aa6dbb44ff7b870b49a4b2d8efb-mob.jpg
try this
bitmap.compress(bitmap.compressformat.jpeg, quality, outstream); here's little example
file file = new file(file.getpath() + "/" + filenamemobile); fileoutputstream fout = new fileoutputstream(file); bmp.compress(bitmap.compressformat.jpeg, 85, fout); fout.flush(); fout.close();
Comments
Post a Comment