networking - Android: Problems downloading images and converting to bitmaps -


I am working on an application that downloads images from the url. The problem is that only some images are being downloaded properly and others are not. First of all, this is a problem code:

  Public Bitmap Download Image (string URL) {HTTP Client Client = New DefaultHttpClient (); HttpResponse response = null; Try {feedback = client.execute (new HttpGet (url)); } Catch (Client Protocol Expansion CP) {log. (LOG_FILE, "Client Protocol Exception"); Return tap; } Hold (IOException ioe) {Log.i (LOG_FILE, "IOE Downloading Image"); Return tap; } Hold (exception e) {Log.i (LOG_FILE, "Other exceptions download image"); Return tap; } // Try changing the bitmap object from the stream {bitmap image = bitmapfinder. Acadestream (Reaction Gates). GetContent ()); If log (image == zero) I (LOG_FILE, "image conversion failed"); Return image; } Hold (exception e) {Log.i (LOG_FILE, "Other exceptions to changing image"); Return tap; }}  

So I have a method that takes the url as a string argument and then download an image, bitmap Rispons stream bitmap through bitmapFactory.decodeStream method Convert it to, and it returns. The problem is that when I'm on a slow network connection (about 3g instead of Wi-Fi), some images are changed blank - not all of them, only some of them use Wi-Fi connections completely Works; All images are downloaded and converted properly

Does anyone know why this is happening? Or better, how can I fix this? How do I go about testing to determine the problem? Any help is amazing; Thanks!

This is a known issue with JPEG decoder. There are two solutions or you can download a byte [] array through a byte [] array using the byte input bar and then decode the array (this is what I do.) Another The solution is that the wrapper inputstream is shown below:

  Public category PatchInputStream FilterInputStream {Public PatchInputStream (InputStream in) extends into {super (in); } Public throws long (long n) IOException {long I = 0L; While (M & L; n) {long _m = in.skip (n-m); Break (_m == 0L); M + = _m; } Return me; }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -