I'm connecting to a server to get 50 bitmaps, and i'm using this function 
for each bitmap:

public static Bitmap getRemoteBitmap(String url) {
        int cont=0; //reintentos
        Bitmap bm = null;
        do{
            if (bm != null){
                if (bm.isRecycled()==false)
                    bm.recycle();
                bm=null;
            }
            HttpClient httpclient = new DefaultHttpClient(); 
            HttpResponse response; 
            try { 
                 ((AbstractHttpClient) 
httpclient).getCredentialsProvider().setCredentials(
                        new org.apache.http.auth.AuthScope(null,-1), 
                        new 
org.apache.http.auth.UsernamePasswordCredentials(MagazineStatus._username, 
MagazineStatus._password)); 

                response = httpclient.execute(new HttpGet(url)); 
                StatusLine statusLine = response.getStatusLine(); 
                if(statusLine.getStatusCode() == HttpStatus.SC_OK) { 
                    try {                   
                        HttpEntity entity = response.getEntity();
                        InputStream content = entity.getContent();
                        bm=BitmapFactory.decodeStream(content );
                        content.close();
                        entity.consumeContent();
                        System.out.println("");
                    }catch(Exception ex) {Log.e("DBF Error",ex.toString());}    
             
                }else { 
                    response.getEntity().getContent().close();
                    throw new IOException(statusLine.getReasonPhrase());
                } 
            }catch(ClientProtocolException cpe) {Log.e("ClientProtocolException 
@ at FPT",cpe.toString());} catch(Exception ex) {Log.e("Exception at 
FETCHPROJECTASK",ex.toString());}
            cont++;     
        }while (bm==null && cont<11);
        System.out.println("INTENTOS PARA BAJARLA: "+cont);
        return bm;
    }

After that, i'm compressing the bitmap with

pageBitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(new 
File(Environment.getExternalStorageDirectory()+"/Dir/"+fm.getId()+"/"+i+".jpg")));

Sometimes is working fine, but sometimes i'm receiving glitched bitmaps 
like this:

[image: Glitched bitmap]

I think that the erroneal bitmap is being received only when the function 
must retry itself with another do while iteration. This happens only with 
the httpclient connection fails and returns a null bitmap.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to