Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java int Android Studio的ImageView图像_Java_Android - Fatal编程技术网

Java int Android Studio的ImageView图像

Java int Android Studio的ImageView图像,java,android,Java,Android,好朋友,我如何将ImageView的图像传递到andrid studio中的int为了能够将其保存到BD中,我通过以下方式从数据库加载图像: Intent intent = getIntent (); Bundle b = intent.getExtras (); AdminSQLiteOpenHelper adminPlants = new AdminSQLiteOpenHelper (this, "Plants", null, 1);

好朋友,我如何将
ImageView
的图像传递到andrid studio中的int为了能够将其保存到BD中,我通过以下方式从数据库加载图像:

Intent intent = getIntent ();
        Bundle b = intent.getExtras ();

        AdminSQLiteOpenHelper adminPlants = new AdminSQLiteOpenHelper (this, "Plants", null, 1);
        SQLiteDatabasePlantsDatabase = PlantsPlants.getWritableDatabase ();

        Cursor file_plants = BaseDeDatosPlantas.rawQuery
                ("SELECT * from species where commonname = '" + b.getString ("name") + "'", null);
        if (file_plantas.moveToFirst ()) {
            tvNameE.setText (b.getString ("name"));
            tvSpeciesE.setText (file_plants.getString (2));
            tvDescripcionE.setText (file_plantas.getString (4));
            imgFotoE.setImageResource (file_plantas.getInt (5)); // Here I send the image to the ImageView
        }
        PlantsDatabase.close ();
在应用程序中,图像在设备上被更改为另一个图像,现在我做相反的事情,从
ImageView
获取图像并将其传递给int,从而能够再次将其保存在BD中

public void SaveE (View view) {
        AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper (this, "Plants", null, 1);
        SQLiteDatabase DataBase = admin.getWritableDatabase ();
        
        Database.execSQL ("update species set description = '" + tvDescripcionE.getText () + "', photo =" + imageResource
                + "where CommonName = '" + tvNameE.getText () + "';"); // This is where I need the int of the image
        Database.close ();
    }

由于
ImageView
可以承载任何类型的
Drawable
,而不仅仅是由资源id指定的类型,因此没有API可以从ImageView中获取资源id

也就是说,在分配资源id时,您始终可以将其作为
标记保存到ImageView:

int resourceId = file_plantas.getInt (5);
imgFotoE.setImageResource (resourceId);
imgFotoE.setTag(resourceId);
然后您可以稍后检索它:

int resourceId = (int) imgFotoE.getTag();

如果图像是从设备加载的,然后从那里加载到数据库中,这怎么可能呢?