首先,将图像存储为ArrayList,并为这些图像创建一个 ImageAdapter,例如在 GridView 中。其次,在 GridView 上设置setOnItemClickListener。
第三,创建一个Intent 来启动您的 ImageViewActivity(或您喜欢的任何名称),然后对这些图像(图像的 ID)执行一个 intent.putExtra(EXTRA_RES_ID)。最后,startActivity(intent)。
或者,根据developer.android.com,
以下是使用日期时间戳为新照片返回唯一文件名的方法中的示例解决方案:
String mCurrentPhotoPath;
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
使用此方法可用于为照片创建文件,您现在可以像这样创建和调用 Intent:
static final int REQUEST_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
...
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
在此处查看更多信息Android Photo Basics