728x90
반응형
SMALL
java
public Main camera extends AppCompatActivity {
@SuppressLint("WrongThread")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
Button Button = (Button) findViewById(R.id.button);
Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 100);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK && data != null) {
Uri uri = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
} catch (IOException e) {
e.printStackTrace();
}
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);
}
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="92dp"
android:layout_height="52dp"
android:layout_marginStart="64dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="21dp"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="334dp"
android:layout_height="449dp"
android:layout_marginTop="96dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
728x90
반응형
LIST
'App Programming > Android Studio' 카테고리의 다른 글
[Android Studio] 카메라 (Camera) (0) | 2023.05.30 |
---|---|
[Android Studio] SQLite 테이블 데이터 존재 여부 확인 (0) | 2023.04.19 |
[Android Studio] 웹뷰 줌 (Zoom) 설정 (0) | 2023.04.17 |
[Android Studio] 뒤로 가기 두 번 눌러 앱 종료하기 (0) | 2023.03.14 |
[Android Studio] 앱 아이콘 변경 (0) | 2023.03.14 |