E / BitmapFactory(没有此类文件或目录)Android API25

时间:2019-10-03 23:19:16

标签: java android bitmapfactory

下午好,我在Android中使用以下代码拍摄照片并在ImageView中显示,当我使用filemanager检查时,文件照片在路径中,但没有在ImageView中显示并显示以下消息:

  

E / BitmapFactory:无法解码流:   java.io.FileNotFoundException:   /storage/emulated/0/S3TAUDIT/photos/S3actual.png(无此文件或   目录)

请我帮忙完成我的应用程序。我使用Android 25 API 7,权限为options.inJustDecodeBounds。我已经审查了所有带有此错误类型的帖子,但没有找到解决方案。

非常感谢。

package com.example.jorge.s3taudit;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Environment;
import android.os.StrictMode;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;

import java.io.File;

public class PICSSECTOR extends AppCompatActivity {

    private final String carpeta_raiz="S3TAUDIT/";
    private final String ruta_imagen=carpeta_raiz+"photos";
    String path;

    ImageView pics1actual;

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

public void pics1actual(View view) {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        File pics1actualpng= new File(Environment.getExternalStorageDirectory(),ruta_imagen);
        boolean isCreada =pics1actualpng.exists();
        String nombre_imagen ="";
        if (isCreada == false){
            isCreada = pics1actualpng.mkdirs();
            nombre_imagen = "S3actual.png";
        }
        if (isCreada==true){
            nombre_imagen = "S3actual.png";
        }
        path = Environment.getExternalStorageDirectory()+File.separator +ruta_imagen+File.separator+ nombre_imagen;

        File pics1actual =new File(path);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(pics1actual));
        startActivityForResult(intent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == 0) {
                MediaScannerConnection.scanFile(this, new String[]{path}, null,
                        new MediaScannerConnection.OnScanCompletedListener() {
                            @Override
                            public void onScanCompleted(String s, Uri uri) {
                                Log.i("RUTA de almacenamiento", "Path: " + path);
                            }
                        });
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = false;
                ImageView pics1actual = (ImageView) findViewById(R.id.s1actual);
                Bitmap bitmap = BitmapFactory.decodeFile(path,options);
                pics1actual.setImageBitmap(bitmap);
          }

    }
}

仅此操作的xml是:

 <ImageView
                android:id="@+id/s1actual"
                android:layout_width="0dp"
                android:layout_height="150dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:background="#DDDDDD" />

 <Button
                android:id="@+id/ButtonPICS1actual"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableStart="@drawable/ic_stat_name"
                android:onClick="pics1actual"
                android:text="PHOTO"
                android:textSize="20dp" />

我在调试器中拥有的这张图片

enter image description here

0 个答案:

没有答案