在Android Studio中将图像存储为值

在Android Studio中将图像存储为值,android,button,Android,Button,这是当用户选择一个图像并将运行此编码(finish())时的代码,如果选择错误的图像,则不要运行finish()。 但我不知道如何使图像作为一个值,我如何选择可绘制的a或b或c和链接到这个功能 if(eyeDected) { if(detectedFrame > 25) { eyeDected =

这是当用户选择一个图像并将运行此编码(finish())时的代码,如果选择错误的图像,则不要运行finish()。 但我不知道如何使图像作为一个值,我如何选择可绘制的a或b或c和链接到这个功能

  if(eyeDected)
                    {
                        if(detectedFrame > 25)
                        {
                            eyeDected = false;
                            detectedFrame = 0;
                            finish();
                        } else {
                            detectedFrame++;
                            Log.d("UNLOCK:", String.valueOf(detectedFrame));
                        }
                    } else {
                        eyeDected = true;
                        detectedFrame++;
                        Log.d("UNLOCK:", String.valueOf(detectedFrame));
                    }
我想问一下如何将绘图/图像存储到值中? 我正在开发一个锁屏应用程序,当用户选择正确的图像将执行解锁功能 这是一个布局显示3个图像,并让用户选择一个锁定屏幕内的图像

在设置中,我将允许用户选择一个图像作为将执行代码的正确图像

set_image.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/new_build_resize_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/setting">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Set Image "
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="38dp"
        android:textColor="@color/abc_primary_text_material_light" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select one graphical passcode as your lock screen."
        android:id="@+id/textView2"
        android:textSize="22dp"
        android:textColor="#1547bb"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true" />

    <ImageButton
        android:layout_width="135dp"
        android:layout_height="140dp"
        android:src="@drawable/a"
        android:id="@+id/imageButton1"
        android:layout_above="@+id/imageView2"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2" />

    <ImageButton
        android:layout_width="126dp"
        android:layout_height="126dp"
        android:src="@drawable/b"
        android:id="@+id/imageView2"
        android:layout_above="@+id/imageView3"
        android:layout_alignParentLeft="true" />

    <ImageButton
        android:layout_width="126dp"
        android:layout_height="126dp"
        android:src="@drawable/c"
        android:id="@+id/imageView3"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="46dp" />

</RelativeLayout>


您可以使用标签或自定义属性来查看
ImageView
也许我不明白,为什么要存储整个图像,而不是在onClick事件中存储与图像关联的值?图像a、图像b或任何名称。如果你真的想要它,我想你可以得到位图
((BitmapDrawable)imageButton.getDrawable()).getBitBitmap()
和base64 it.eyedeced来自mainactivity.java,但目前我还没有指向set_image.xml的image.java链接