复制代码代码如下 :
최종 파일 ImageFile = 새 파일 (getCachedir (). getPath () + "/img/" + p.image);
image.setvisibility (view.gone);
View.FindViewById (r.id.imageloading) .setvisibility (view.visible);
(새 Asynctask <void, void, bitmap> () {
@보수
보호 된 비트 맵 doinbackground (void ... params) {
노력하다 {
비트 맵 이미지;
if (! imagefile.exists () || imagefile.length () == 0) {
image = bitmapfactory.decodestream (new URL)
"http://example.com/images/"
+ p.image) .openstream ());
image.compress (bitmap.compressformat.jpeg, 85,
새 FileOutputStream (ImageFile));
image.recycle ();
}
image = bitmapfactory.decodefile (imageFile.getPath (),
비트 맵 옵션);
리턴 이미지;
} catch (marlormedurlexception ex) {
// TODO 자동 생성 캐치 블록
ex.printstacktrace ();
널 리턴;
} catch (ioException ex) {
// TODO 자동 생성 캐치 블록
ex.printstacktrace ();
널 리턴;
}
}
@보수
보호 된 void OnPostExecute (BitMap Image) {
if (view.getTag ()! = p) //보기가 재활용되었습니다.
반품;
View.FindViewById (r.id.imageloading) .setvisibility (
view.gone);
View.FindViewByid (R.id.Image)
.SetVisibility (View.Visible);
((ImageView) View.FindViewById (r.id.Image))
.SetImageBitMap (이미지);
}
}).실행하다();