´Ü¸»¿¡ ÀÖ´Â Ä«¸Þ¶ó ¾ÛÀ» ¶ç¿öÁÖ´Â ¹æ¹ý
¾Û¿¡¼ »ó´çÈ÷ ¸¹ÀÌ »ç¿ëÇÏ´Â ±â´É
ÀÎÅÙÆ®¸¦ »ç¿ëÇÏ´Â ¹æ¹ýÀ¸·Î ¾Èµå·ÎÀ̵å ÆùÀÇ ±âº» Ä«¸Þ¶ó ¾ÛÀ» ÀÌ¿ëÇؼ
ÃÔ¿µÇÑ °á°ú¸¦ °¡Á®¿À´Â ¹æ¹ý°ú Á÷Á¢ ÃÔ¿µÇÏ´Â ±â´ÉÀ» ¸¸µå´Â ¹æ¹ýÀÌ ÀÖ´Ù.
* Á÷Á¢ ÃÔ¿µ ±â´ÉÀ» ±¸ÇöÇÒ¶©, Ä«¸Þ¶ó ¹Ì¸®º¸±â¸¦ À§Çؼ´Â ¿µ»óÀ» ½Ç½Ã°£À¸·Î º¸¿©ÁÖ±â À§Çؼ´Â ¼º´ÉÀÌ Áß¿äÇؼ Çϵå¿þ¾î °¡¼Ó ±â´ÉÀ» »ç¿ëÇÒ ¼ö ÀÖ´Â ¼Çǽººä(SurfaceView)¸¦ »ç¿ëÇÑ´Ù.
¾Æ·¡ ¼Ò½º´Â ¾Èµå·ÎÀ̵åÀÇ ±âº» ¾ÛÀ» ÀÌ¿ë(Intent)Çؼ ÃÔ¿µÇÏ´Â ¿¹Á¦ ÀÌ´Ù.
1. ·¹À̾ƿô ÆÄÀÏ
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="onButtonCamera" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_below="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
2. ÀÚ¹Ù¼Ò½º
ImageView imageView;
File outputFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
File storageDir = Environment.getExternalStorageDirectory();
outputFile = new File(storageDir, "output.jpg");
}
public void onButtonCamera(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outputFile));
startActivityForResult(intent, 1001);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 1001) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeFile(outputFile.getAbsolutePath(), options);
imageView.setImageBitmap(bitmap);
}
}
3. Æ۹̼Ç
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.camera" android:required="true"></uses-permission>