我想将来自互联网链接的图像添加到我的 sqlite 数据库中,我尝试将其转换为位图,并使用 setImageBitmap 但它没有用
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static Bitmap readBitmapFile(String path){
return BitmapFactory.decodeFile(path);
}
public static ArrayList<Comics> initDataForComics(){
data.add(new Comics("SakamotoDays", getBitmapFromURL("https://i.pinimg.com/564x/b1/3e/78/b13e78c4349cceeae0194156086699be.jpg") ));
return data;
}
}
@Override
public void onBindViewHolder(@NonNull ComicsVH holder, int position) {
Comics comics = lstComics.get(position);
holder.imgComics.setImageBitmap(comics.getImage());
holder.titleComics.setText(comics.getName());
}
应用程序未启动 我可以通过其他方式将图像添加到我的数据库吗?