728x90
반응형
SMALL
카메라 API
Android 프레임워크에는 기기에서 이용 가능한 다양한 카메라와 카메라 기능에 대한 지원을 포함하여 애플리케이션에서 사진과 동영상을 캡처할 수 있도록 한다.
gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<Button
android:id="@+id/btnTakePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="showCameraBtn"
android:text="사진 찍기"
android:textStyle="bold" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/capturedImage"
android:layout_above="@+id/btnTakePicture"/>
</RelativeLayout>
java
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
ImageView image1 ;
private int requestCode=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView)findViewById(R.id.capturedImage);
}
public void showCameraBtn(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, requestCode );
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if( resultCode==RESULT_OK) {
Bitmap bitmap=(Bitmap)data.getParcelableExtra("data");
image1.setImageBitmap(bitmap);
}
}
}
https://developer.android.com/guide/topics/media/camera?hl=ko#java
728x90
반응형
LIST
'App Programming > Android Studio' 카테고리의 다른 글
[Android Studio] 다이얼로그 (Dialog) (0) | 2022.12.29 |
---|---|
[Android Studio] 공유하기 기능 (Android Sharesheet) (0) | 2022.12.22 |
[Android Studio] Google API (0) | 2022.12.01 |
[Android Studio] 하이퍼링크 (Hyperlink) (0) | 2022.11.25 |
[Android Studio] 버튼 클릭시 버튼 색상 변경 (0) | 2022.11.21 |