【发布时间】:2018-01-04 18:15:17
【问题描述】:
这是我尝试过的代码。
我没有使用 Glide 获取 bmp 中的图像,当我在将图像转换为 byte[] 的方法中传递空 bmp 时,就会发生错误。
新的 AsyncTask() {
@Override
protected byte[] doInBackground(Void... voids) {
Looper.prepare();
byte[] byteimage = new byte[0];
Bitmap bmp1;
try {
bmp= Glide.with(specificrecipe.this)//bmp is global
.load(url2img)
.asBitmap()
.into(100,100)
.get();
byteimage=getBytes(bmp);//here I'm not getting the image in bmp
//ByteArrayOutputStream stream = new ByteArrayOutputStream();
//bmp.compress(Bitmap.CompressFormat.PNG, 0, stream);//null object refrence -> bmp
//byteimage=stream.toByteArray();
//byteimage1.add(0,byteimage);
// initialize(bmp);
}catch (final ExecutionException e){e.printStackTrace();}
catch (final InterruptedException e){e.printStackTrace();}
return byteimage;
}
//@Override
//protected void onPostExecute(byte[] Bytearray){
//byteimage1=Bytearray;
//}
}.execute();
【问题讨论】:
-
如果要转换成位图。 Glide lib 会为你做这件事。
-
看到在将 URL 传递给 Glide 后我没有收到 BMP 中的图像 null 异常发生。
标签: java android try-catch android-glide