Android
Take a photo with a camera app and get the thumbnail
J-sean
2019. 10. 18. 16:42
반응형
Explains how to take a photo and get the thumbnail of it in an easy way.
기기의 카메라 앱을 실행 시키고 사진을 찍어 썸네일을 가져 온다.
<AndroidManifest.xml>
1 | <uses-feature android:name="android.hardware.camera" android:required="true"/> |
<MainActivity.java>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public class MainActivity extends AppCompatActivity { static final int REQUEST_IMAGE_CAPTURE = 1001; ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = findViewById(R.id.imageView); Button button = findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } } }); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { Bundle extras = data.getExtras(); Bitmap bitmap = (Bitmap)extras.get("data"); imageView.setImageBitmap(bitmap); } } } |
Run the app and click CAMERA button.
Take a picture.
Get the thumbnail.
반응형