我想要sdcard中的任何一个图像。 我只知道image
的名字。 但我如何检索我的程序(包括路径)内的特定图像。也可以转换成bitmap
或存储在位图变量 我该怎么做? 谢谢android如何获取sd卡中的特定图像
回答
在这里,你可以显示SD卡的所有图像,当你点击其中一个,你选择图片的路径:
try {
// Set up an array of the Thumbnail Image ID column we want
String[] projection = { MediaStore.Images.Thumbnails._ID };
// Create the cursor pointing to the SDCard
cursor = managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null, MediaStore.Images.Thumbnails.IMAGE_ID);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
GridView sdcardImages = (GridView) findViewById(R.id.gallary);
sdcardImages.setAdapter(new ImageAdapter(this));
// Set up a click listener
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v,
int position, long id) {
// Get the data location of the image
String[] projection = { MediaStore.Images.Media.DATA };
cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null, null);
columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToPosition(position);
// Get image filename
String imagePath = cursor.getString(columnIndex);
// Use this path to do further processing, i.e. full screen
// display
}
});
} catch (Exception e) {
e.printStackTrace();
}
这里是ImageAdapter:
/**
* Adapter for our image files.
*/
private class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context localContext) {
context = localContext;
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image based on the provided URI
picturesView.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""
+ imageID));
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
picturesView
.setLayoutParams(new GridView.LayoutParams(100, 100));
} else {
picturesView = (ImageView) convertView;
}
return picturesView;
}
}
如果你知道确切的路径和图像名称,您可以通过使用得到Bitmap
:
Bitmap bitmap = BitmapFactory.decodeFile("yourImageDirectory" + "yourImageName.png");
我想知道sd卡中图像的路径是什么? – Jyosna
我知道。在'cursor'中有关于SDCard中图像的所有信息。所以如果你循环使用光标,你可以得到你想要的完整图像路径。 –
我查询缩略图图像并在此变量中:String imagePath = cursor.getString(columnIndex); 我得到了:/mnt/sdcard/DCIM/.thumbnails/1329694769950.jpg女巫是通往缩略图的路径,而不是原始图像。我想问你,如果你知道,我如何获得完整图像(原始图像)的路径?谢谢 –
- 1. 如何从android中的SD卡获取指定的图像?
- 2. 从SD卡中获取图像 - android
- 3. Android从SD卡获取图像
- 4. 如何从android中的SD卡获取图像?
- 5. Android:从SD卡上的特定位置获取缩略图
- 6. 从SD卡读取图像的android
- 7. 如何获取存储在SD卡中的图像的数量
- 8. Android:如何从SD卡上传图像
- 9. Android:如何:从SD卡显示图像?
- 10. 如何从android中的SD卡获取指定的视频?
- 11. 如何在Android中获取SD卡中的所有图像文件?
- 12. 从Gopro SD卡获取图像Objective-c
- 13. 如何获取存储在SD卡上的图像的Uri?
- 14. Android - 获取Uri在SD卡上的图像
- 15. 如何在Android中拍摄照片或SD卡后获取图像名称
- 16. android viewflow从SD卡刷卡图像
- 17. 如何从android中的SD卡图像创建位图?
- 18. 如何获取图像轮廓(或从图像中获取特定颜色?)-ANDroid
- 19. 如何从卡组图像中取出特定的卡片?
- 20. 从android中读取SD卡中的特定文件
- 21. 读取SD卡中的Android
- 22. Android:从SD卡中删除图像
- 23. 我们如何从基于Android中的时间戳的独特名称的SD卡获取图像
- 24. 如何从SD卡获取所有图像?
- 25. 如何从存储在SD卡上的图像获取图像路径
- 26. 从Android的SD卡删除图像
- 27. Android的图像保存到SD卡
- 28. 如何从Android SD卡和内部存储器获取图像和视频
- 29. Android-如何使用SD卡中的图像集制作视频?
- 30. android - 如何将图像复制到SD卡中的文件夹
你知道图像或图像名称的完整路径吗? –