正在關注the android tutorial,我可以拍照。在Android應用程序中顯示拍攝的圖片
public class TakePhotoActivity extends Activity {
private Uri fileUri;
// I am not sure what this is for yet
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo);
// Show the Up button in the action bar.
setupActionBar();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri();
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
private static Uri getOutputMediaFileUri() {
return Uri.fromFile(getOutputMediaFile());
}
private static File getOutputMediaFile() {
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MyCameraApp");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
return new File(mediaStorageDir.getPath() + File.separator + "IMG_"
+ timeStamp + ".jpg");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE == requestCode) {
if (RESULT_OK == resultCode) {
// Toast.makeText(this, "Image saved to:\n" + data.getData(),
// Toast.LENGTH_LONG).show();
}
}
}
}
現在我想要顯示我剛剛拍攝的圖片,使用onActivityResult
。有沒有人有一些代碼來做到這一點?
編輯顯示XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TakePhotoActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/desc" />
</RelativeLayout>
我是初學者。我正在尋找我能理解的東西。我希望得到的代碼少得多。 – learner 2013-03-12 00:14:01
現在是怎麼回事,你會得到一個非常高的分辨率的位圖和sendBroadcast將更新您的畫廊與你拍的照片,然後在那裏做任何你想要的位圖 – JRowan 2013-03-12 00:27:51
如果你不發送像那樣的廣播圖片不會出現在您的手機中,直到您下次打開手機 – JRowan 2013-03-12 00:32:11