2017年3月17日金曜日

Andriod Intent Camera

Andriod Intent Camera



public class MainActivity extends AppCompatActivity {
    protected File file;
    protected Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t1();
    }

    protected void t1() {
        file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "00000aaaa.jpg");
        uri = Uri.fromFile(file);
        Intent intent = new Intent();
        intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, 99);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 99 && resultCode == RESULT_OK) {
            view2();
        }
    }

    protected void view2() {
        Display display = getWindowManager().getDefaultDisplay();
        Point p = new Point();
        display.getSize(p);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getAbsolutePath(), options);

        int samsize = Math.max(options.outHeight / p.y, options.outWidth / p.x);
        options.inJustDecodeBounds = false;
        options.inSampleSize = samsize;

        ImageView imageView = (ImageView) findViewById(R.id.vvvv);
        Bitmap bt = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
        imageView.setImageBitmap(bt);
    }
}

0 件のコメント: