1

imageView に画像を表示したい、パスをデータベースに保存し、そのパスを使用して imageView に画像を表示したい。

String path = Utility.GetColumnValue(testdata, "path");

これは、パスの形式で値を返します >> /drawable/image

その後

ImageView img = (ImageView) findViewById(R.id.imageview);
img.setImageURI(Uri.parse(path));

しかし、私のアプリは何か間違ってクラッシュします

4

4 に答える 4

2

そのようなパスからビットマップを取得できます

 Bitmap bmp = BitmapFactory.decodeFile(img_path );
    img.setImageBitmap(bmp);

またはこれを試すことができます

String path= "@drawable/myresource.png";
int imageResource = getResources().getIdentifier(path, null, getPackageName());
Drawable res = getResources().getDrawable(imageResource);
img.setImageDrawable(res);
于 2013-08-29T08:14:59.403 に答える
1

これを試して:

ImageView img = (ImageView) findViewById(R.id.imageview);
InputStream inputStream = getClass().getResourceAsStream(path);
img.setImageDrawable(Drawable.createFromStream(inputStream, ""));
于 2013-08-29T08:14:34.330 に答える
0
Bitmap bmp=BitmapFactory.decodeFile(path);
img.setImageBitmap(bmp);
于 2013-08-29T08:14:52.150 に答える