사진을 캡처하여 ImageView에 표시하려고합니다.사진을 캡처하여 Android의 ImageView에 전체 크기로 표시하십시오.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0)
{
if(imageFile.exists())
{
Toast.makeText(this,"file saved!",Toast.LENGTH_SHORT).show();
ImageView myImage = (ImageView) findViewById(R.id.imageView1);
Bitmap bmImg = BitmapFactory.decodeFile("imageFile");
myImage.setImageBitmap(bmImg);
}
else
{
Toast.makeText(this,"file not saved!",Toast.LENGTH_SHORT).show();
}
}
}
은 XML 레이아웃은 다음과 같습니다 :
나는 이미지가 이미지 뷰에서 전체 크기로 표시되지 수
public void takePhoto (View view) {
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "myPhoto.jpg";
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(baseDir + File.separator + fileName);
Uri uri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
}
을하지만 : 첫 번째 부분은 성공적으로 수행되고 이미지가 저장됩니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.android.trial3.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shoot"
android:onClick="takePhoto"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView1"/>
</LinearLayout>
그리고 Manifes t.XML 파일 :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.trial3">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
나는 다음과 같은 오류를 받고 있어요 : 어떤 도움에 감사드립니다
BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0
.