Android 将图像链接到imageview以绘制

Android 将图像链接到imageview以绘制,android,url,Android,Url,我从url获取图像,但我想将其存储到我的绘图设备,如何存储?apk中的所有内容都将是只读的。 所以你不能给drawable写信 您必须使用“blob”来存储图像 例如:将图像存储到数据库中 ImageView img1; img1 = (ImageView) findViewById (R.id.img1); URL newurl = new URL("http://10.0.2.2:80/Gallardo/Practice/files/images/donut.jpg

我从url获取图像,但我想将其存储到我的绘图设备,如何存储?

apk中的所有内容都将是只读的。 所以你不能给drawable写信

您必须使用“blob”来存储图像

例如:将图像存储到数据库中

ImageView img1;
    img1 = (ImageView) findViewById (R.id.img1);

        URL newurl = new URL("http://10.0.2.2:80/Gallardo/Practice/files/images/donut.jpg");
        Bitmap mIcon_val = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream());
        img1.setImageBitmap(mIcon_val);
从数据库中检索图像的步骤

public void insertImg(int id , Bitmap img ) {   


    byte[] data = getBitmapAsByteArray(img); // this is a function

    insertStatement_logo.bindLong(1, id);       
    insertStatement_logo.bindBlob(2, data);

    insertStatement_logo.executeInsert();
    insertStatement_logo.clearBindings() ;

}

 public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0, outputStream);       
    return outputStream.toByteArray();
}

您还可以检查此项

在运行apk时,无法将图像放置在可绘制文件夹中。。将图像保存到SD卡是可能的。

您可以使用以下方法构造Drawable:

您可以将其设置为ImageView,如下所示:

Drawable drawable = new BitmapDrawable(getResources(), mIcon_val);

我认为那不是个好主意。。为什么不能保存到SDCard数据库呢?SQLite?是的,可以试试,先生,请问这是什么线路?insertStatement_logo.bindLong(1,id);insertStatement_logo.bindBlob(2,数据);insertStatement_logo.executeInsert();insertStatement_logo.clearBindings();
Drawable drawable = new BitmapDrawable(getResources(), mIcon_val);
img1.setImageDrawable(drawable);