我怎样才能捕捉Android的图像,并将它显示在画廊? [英] How can I capture an image in Android and have it show up in the gallery?
本文介绍了我怎样才能捕捉Android的图像,并将它显示在画廊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在拍摄图像显示在画廊,但现在他们都没有,我想不出为什么。这是我的code:
I was capturing images before that were showing up in the gallery, but now they are not and I can't figure out why. Here is my code:
ContentValues values = new ContentValues();
values.put(android.provider.MediaStore.Images.Media.IS_PRIVATE, false);
String name = "ugc_" + String.valueOf(System.currentTimeMillis());
values.put(android.provider.MediaStore.Images.Media.TITLE, name);
imageURI = getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
我也试过: values.put(android.provider.MediaStore.Images.Media.IS_PRIVATE,0); 还可以把在该值,但似乎没有现在的工作。
I've also tried: values.put(android.provider.MediaStore.Images.Media.IS_PRIVATE, 0); as well as leaving at that value, but nothing seems to work now.
推荐答案
非常喜欢不是pretty的,但是这是我怎么做。需要注意的是由于错误,将文件保存为1/16全分辨率(在每个维度1/4)。
Very much not pretty, but this is how I'm doing it. Note that due to a bug, the file saved is 1/16 the full resolution (1/4 in each dimension).
String SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "tmpPhoto.jpg";
Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new
File(SD_CARD_TEMP_DIR)));
startActivityForResult(takePictureFromCameraIntent, TAKE_PICTURE_WITH_CAMERA);
。 。
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Picture taken from camera
if (requestCode == TAKE_PICTURE_WITH_CAMERA) {
if (resultCode == Activity.RESULT_OK) {
// http://code.google.com/p/android/issues/detail?id=1480
//Toast.makeText(AddPhotos.this, "" + data, Toast.LENGTH_SHORT).show();
// on activity return
File f = new File(SD_CARD_TEMP_DIR);
try {
Uri capturedImage =
Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(),
f.getAbsolutePath(), null, null));
Log.i("camera", "Selected image: " + capturedImage.toString());
f.delete();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
Log.i("Camera", "Result code was " + resultCode);
}
}
}
这篇关于我怎样才能捕捉Android的图像,并将它显示在画廊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文