在此question中解释了如何获取图像的名称
File f = new File(picturePath);
String imageName = f.getName();
然而,我将图像作为一个意图,如何得到它的名称?
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
另一个子问题。
我正在将图片从图库上传到服务器,所以我虽然上传到服务器的图片名称应该与图库添加日期相同?你有另外一种方法可以帮我吗?
这是php,将文件命名为静态,这是不好的
$base=$_REQUEST['image'];
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploaded_images.jpg', 'wb');
fwrite($file, $binary);
修改
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
// startActivityForResult(
// Intent.createChooser(intent, "Complete action using"),2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
//file name
filePath = data.getData();
try {
// Bundle extras2 = data.getExtras();
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
// imageview.setImageBitmap(bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte imageInByte[] = stream.toByteArray();
Intent i = new Intent(this,
AddImage.class);
i.putExtra("image", imageInByte);
startActivity(i);
} catch (IOException e) {
e.printStackTrace();
}
}
}