我想从图库中获取图像时获取图像名称。怎么做?以下是我的代码。我不知道如何继续。
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, IMAGE_PICKER_SELECT);
}
});
return v;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IMAGE_PICKER_SELECT && resultCode == Activity.RESULT_OK) {
bitmap = getBitmapFromCameraData(data, mainActivity);
bitmap = getBitmapFromCameraData(data, mainActivity);
profileImageView.setImageBitmap(bitmap);
uploadImage();
}
}
private Bitmap getBitmapFromCameraData(Intent data, Context context) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
return BitmapFactory.decodeFile(picturePath);
}
答案 0 :(得分:-1)
以下代码可帮助您获取所选文件的图像名称:
private String getFileName(Uri selectedImage){
File f = new File(picturePath);
String imageName = f.getName();
return imageName;
}
快乐编码!!!
答案 1 :(得分:-1)
您获得的ParentVC *parentVC = [self.storyboard instantiateViewControllerWithIdentifier:@"IDParentVC"];
ChildVC *childVC = [self.storyboard instantiateViewControllerWithIdentifier:@"IDChildVC"];
[childVC.view setFrame:CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[parentVC addChildViewController:childVC];
[parentVC.view addSubview:childVC.view];
[childVC didMoveToParentViewController:parentVC];
包含图片名称
从那里拿出来。
例如
picturepath