Skip to content Skip to sidebar Skip to footer

Image View Problem

ImageView img; TextView tv; Parser p= new Parser(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(

Solution 1:

According to this link, there is a bug in the previous versions of BitmapFactory.decodeStream. It exists at least at the Android 2.1 SDK.

This class fixes the problem:

classFlushedInputStreamextendsFilterInputStream {
    publicFlushedInputStream(InputStream inputStream) {
        super(inputStream);
    }

    @Overridepubliclongskip(long n)throws IOException {
        longtotalBytesSkipped=0L;
        while (totalBytesSkipped < n) {
            longbytesSkipped= in.skip(n - totalBytesSkipped);
            if (bytesSkipped == 0L) {
                  intibyte= read();
                  if (ibyte < 0) {
                      break;  // we reached EOF
                  } else {
                      bytesSkipped = 1; // we read one byte
                  }
           }
            totalBytesSkipped += bytesSkipped;
        }
        return totalBytesSkipped;
    }
}

And image should be downloaded so:

//I'm not sure whether this line works, but just in case I use another approach//InputStream is = (InputStream)new URL(image).getContent()DefaultHttpClientclient=newDefaultHttpClient();
HttpGetrequest=newHttpGet(imageUrl);
HttpResponseresponse= client.execute(request);
InputStreamis= response.getEntity().getContent();
//Use another streamFlushedInputStreamfis=newFlushedInputStream(is);
bmp = BitmapFactory.decodeStream(fis);

Post a Comment for "Image View Problem"