【发布时间】:2013-12-08 17:48:10
【问题描述】:
我有以下情况:从我的第一个活动开始,我从相机拍摄图像,然后打开一个新活动,应在其中预览 iage 并将其作为 httpPOST 请求中的 FILE 参数上传到服务器。
在我的第一个活动中,我使用了以下代码:
public void onClick(View v) {
String fileName = "temp.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE,fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,RESULT_LOAD_IMAGE_FROM_CAMERA);
}
和 onMyActivityResult 我有:
if (requestCode == RESULT_LOAD_IMAGE_FROM_CAMERA
&& resultCode == RESULT_OK && null != data) {
System.out.println("Photo selected from the camera");
String[] projection = {MediaStore.Images.Media.DATA};
//Uri selectedImage = data.getData();
Cursor cursor = getContentResolver().query(mCapturedImageURI, projection, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
//int columnIndex = cursor.getColumnIndex(projection[0]);
//file path of captured image
picturePath = cursor.getString(columnIndex);
//file path of captured image
File f = new File(picturePath);
String filename = f.getName();
Toast.makeText(CommunityMain.this, "Your Path:"+picturePath, 2000).show();
Toast.makeText(CommunityMain.this, "Your Filename:"+filename, 2000).show();
cursor.close();
Intent myIntent = new Intent(CommunityMain.this,PhotoPostActivity.class);
startActivity(myIntent);
图片保存在图库中,我确实看到了图片路径。
当我的 photoPost 活动打开时,我确实有:
f = new File(CommunityMain.picturePath);
System.out.println("Picture path:"+CommunityMain.picturePath);
ImageButton image = (ImageButton) findViewById(R.id.photo1);
image.setImageBitmap(BitmapFactory
.decodeFile(CommunityMain.picturePath));
图片路径一样,但是我的ImageButton没有设置。
我明白了:
12-08 17:37:22.670: E/BitmapFactory(13357): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/1386524213331.jpg: open failed: ENOENT (No such file or directory)
但路径与 toast 消息相同。我错过了什么?
我还需要能够获取文件 f,因为我的 HttpPost 请求需要它。
编辑:问题在于图片路径。我得到的图像与保存图像的方式不同? 我看到一个类似上面的数字,照片中的实际路径有类似 IMG_2313.jpg 之类的东西。
【问题讨论】:
-
拉取文件你看到了吗? adb 拉 /storage/emulated/0/DCIM/Camera/1386524213331.jpg 。 ?
-
@Snicolas 你能看到我的编辑吗?
标签: android android-intent camera