前回、カメラを起動する方法を書きました。
で、その時は、サムネイルの表示だったのですが、今回は、とった写真をそのまま表示する方法について。
static final int REQUEST_IMAGE_CAPTURE = 1; private Uri imageUri; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US).format(new Date()); String mCurrentPhotoFileName = "JPEG_MEMO_" + timeStamp + "_"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, mCurrentPhotoFileName); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri); startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }上のプログラムでカメラを起動し、下のプログラムで画像を表示させます。
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { ImageView imageView = (ImageView) findViewById(R.id.imageview); imageView.setImageURI(imageUri); }問題は、端末を傾けてしまうと画像が表示されなくなってしまうこと。
なので、この問題はまた改めて考えたい。
参考URL
インテントでカメラを呼び出す方法の補足(主に、Xperia 2.1問題対応)
0 コメント:
コメントを投稿