我正在开发一个应用程序,我试图通过图库将图像加载到我的应用程序。我正在使用Intent
从图库中获取图片。存储在内部存储器中的图像完全在应用程序中,但存储在外部存储器中的图像将变为空白。
从图库中获取图片的代码:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
这是获取图像的位图和绝对路径(getPath()返回图像的绝对路径)的代码:
Bitmap bm = null;
String selectedImagePath = null;
if (data != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
bm = scaleDownLargeImageWithAspectRatio(bm);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 90, bytes);
byte[] byteArray = bytes.toByteArray();
strProfileImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
selectedImagePath = getPath(HomeScreenActivity.this, data.getData());
Log.e("ImagePath Gallery", data.getData().toString());
} catch (IOException e) {
e.printStackTrace();
}
if (selectedImagePath != null) {
Uri currentImageUri = null;
if (Build.VERSION.SDK_INT >= 24) {
// wrap File object into a content provider. NOTE: authority here should match authority in manifest declaration
currentImageUri = FileProvider.getUriForFile(HomeScreenActivity.this, "com.example.sravanthiv.consumermobileapp_nonclinical_android.fileprovider", new File(selectedImagePath)); // use this version for API >= 24
} else {
currentImageUri = Uri.fromFile(new File(selectedImagePath));
}
}
我使用currentImageUri
在我的应用程序中加载图像。但有些是空白的(存储在外部存储器中),有些正在变得完美(存储在内部存储器中)。
我正在使用Picasso来加载图片: Picasso.with(mContext).load(Uri.parse(imagesList.get(currentPosition))).resize(135,135).centerCrop().into(holder.selfie_Imageview);
无法加载此路径:
content://com.example.android.fileprovider/all_dirs/DCIM/Camera/IMG_20171226_161309.jpg
但是它能够加载此路径:
content://com.example.android.fileprovider/all_dirs/IMG_20171226_161309.jpg
答案 0 :(得分:0)
试试这个解决方案:
issued_date
{
"cols": [
{"id":"","label":"Sold Year","pattern":"","type":"string"},
{"id":"","label":"Unit Price","pattern":"","type":"number"}
],
"rows": [{"c":[{"v":"2006","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2007","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2008","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2009","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2010","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2011","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2012","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2013","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2014","f":null},{"v":"0","f":"$0"}]},{"c":[{"v":"2015","f":null},{"v":"10700","f":"$10,700"}]},{"c":[{"v":"2015","f":null},{"v":"1280","f":"$1,280"}]},{"c":[{"v":"2016","f":null},{"v":"2500","f":"$2,500"}]},{"c":[{"v":"2016","f":null},{"v":"80500","f":"$80,500"}]},]}
执行此操作:
private void galleryIntent() {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, Util.SELECT_FILE);
}
从图库所选图片中获取结果
onActivityResult
忘记图片真实路径
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == Util.SELECT_FILE) {
onSelectFromGalleryResult(data);
}
}
}
希望这有助于你...如果你需要任何帮助,你可以问