android - android-imageView dosent显示在galaxy上的图像,而它在其他设备上工作

android - android-imageView dosent显示在galaxy上的图像,而它在其他设备上工作,第1张

我不知道为什么会这样。 首先,我按下“相机”按钮 然后相机应用程序开始工作我拍照并保存。 然后我应该看到我的屏幕上的图片,但它显示图片颠倒然后它消失了。它适用于其他设备。     公共类CameraActivity扩展了Activity {

private Button btnCamera;
private ImageView ivCapture;
private static final int ACTIVITY_START_CAMERA_APP = 0;
private String mImageFileLocation = "";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    btnCamera = (Button)findViewById(R.id.btnCamera);
    ivCapture = (ImageView)findViewById(R.id.ivCapture);
    btnCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            takePhoto(v);
        }
    });
}
public void takePhoto(View view){
    Intent callCameraApplicationIntent = new Intent();
    callCameraApplicationIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
    File photoFile = null;
   try{
        photoFile = getFile();
    }catch(IOException e){
        e.printStackTrace();
    }

    startActivityForResult(callCameraApplicationIntent, ACTIVITY_START_CAMERA_APP);
}

private File getFile() throws IOException {

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "IMAGE_"  timeStamp   "_";
        File storageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

         File image = null;

        image = File.createTempFile(imageFileName, ".jpg", storageDirectory);

         mImageFileLocation = image.getAbsolutePath();

        return image;

}
protected void onActivityResult(int requestCode,int resultCode,Intent data){
    if(requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK){
        ivCapture.setImageDrawable(Drawable.createFromPath(mImageFileLocation));}}}

清单

<?xml version="1.0" encoding="utf-8"?>

<uses-feature android:name="android.hardware.camera2"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"   />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".CameraActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

最佳答案:

0 个答案:

没有答案
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复