复制代码代码如下:
Archivo final ImageFile = nuevo archivo (getCachedir (). getPath () + "/img/" + p.image);
Image.setVisibility (ver.gone);
ver.FindViewById (r.id.imageloading) .SetVisibility (View.Visible);
(nuevo AsyncTask <void, void, bitmap> () {
@Anular
mapa de bits protegido doinbackground (void ... params) {
intentar {
Imagen de mapa de bits;
if (! ImageFile.Exists () || imageFile.Length () == 0) {
Image = bitmapFactory.DecodeStream (nueva URL (
"http://example.com/images/"
+ P.Image) .OpenStream ());
Image.Compress (bitmap.compressformat.jpeg, 85,
nuevo FileOutputStream (ImageFile));
Image.Recycle ();
}
Image = BitMapFactory.DecodeFile (ImageFile.getPath (),
mapote de bits);
imagen de retorno;
} catch (malformedurexception ex) {
// bloque de captura generado automático
Ex.PrintStackTrace ();
regresar nulo;
} catch (ioException ex) {
// bloque de captura generado automático
Ex.PrintStackTrace ();
regresar nulo;
}
}
@Anular
Vacío protegido OnPostexecute (imagen de mapas de bits) {
if (ver.gettag ()! = p) // La vista fue reciclada.
devolver;
ver.findViewByid (r.id.imageloading) .SetVisibility (
Ver.gone);
Ver.FindViewById (R.ID.Image)
.SetVisibility (View.Visible);
((ImageView) View.FindViewById (R.ID.Image))
.SetImageBitMap (imagen);
}
}).ejecutar();