子线程里面裁剪图片(540px*540px),获取到Bitmap
//glide框架居中裁剪图片 540*540px(该方法是耗时操作)
new Thread(new Runnable() {
@Override
public void run() {
try {
bitmap = Glide.with(getActivity()).load(realRoomImageUrl).asBitmap().centerCrop().into(540,540).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(100);
}
}).start();
handler里面显示
private static class MyHandler extends Handler {
private WeakReference activityWeakReference;
public MyHandler(RoomTestBeforeFragment fragment) {
activityWeakReference = new WeakReference(fragment);
}
@Override
public void handleMessage(Message msg) {
RoomTestBeforeFragment fragment = activityWeakReference.get();
if (fragment != null) {
switch (msg.what) {
case 100:
fragment.ivShow.setImageBitmap(fragment.bitmap);
break;
default:
break;
}
}
}
}