参照ボタンを使用して画像のファイルパスを取得しています....その後、ファイルパスを使用してこの画像を画像ビューに設定したい
55335 次
4 に答える
41
あなたがオブジェクトFile
を意味するFile
場合、私は試します:
File file = ....
Uri uri = Uri.fromFile(file);
imageView.setImageURI(uri);
于 2013-04-04T14:56:12.230 に答える
9
このコードを試すことができます:
imageView.setImageBitmap(BitmapFactory.decodeFile(yourFilePath));
BitmapFactory は、指定された画像ファイルを Bitmap オブジェクトにデコードし、それを imageView オブジェクトに設定します。
于 2013-04-04T14:57:54.083 に答える
8
ファイルから画像を設定するには、次のようにする必要があります。
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg"); //your image file path
mImage = (ImageView) findViewById(R.id.imageView1);
mImage.setImageBitmap(decodeSampledBitmapFromFile(file.getAbsolutePath(), 500, 250));
時期decodeSampledBitmapFromFile
:
public static Bitmap decodeSampledBitmapFromFile(String path,
int reqWidth, int reqHeight) { // BEST QUALITY MATCH
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight) {
inSampleSize = Math.round((float)height / (float)reqHeight);
}
int expectedWidth = width / inSampleSize;
if (expectedWidth > reqWidth) {
//if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
inSampleSize = Math.round((float)width / (float)reqWidth);
}
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
数値 (この場合は 500 と 250) をいじって、 のビットマップの品質を変更できますImageView
。
于 2013-04-04T15:00:32.100 に答える
2
ファイルから画像をロードするには:
Bitmap bitmap = BitmapFactory.decodeFile(pathToPicture);
pathToPicture
あなたが正しいと仮定すると、このビットマップ画像をImageView
好きなものに追加できます
ImageView imageView = (ImageView) getActivity().findViewById(R.id.imageView);
imageView.setImageBitmap(BitmapFactory.decodeFile(pathToPicture));
于 2017-01-03T05:52:24.350 に答える