Setting ImageView image using path of file from external storage

后端 未结 1 1802
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 05:30

Hi I wanted to change the image of my ImageView using a path I have saved on my SQLite database. Well what I want to achieve is for this runs per second whenever the image i

相关标签:
1条回答
  • 2021-01-06 06:05

    check this if it helps you.

    preview.setImageURI(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Echo/Images/"+file_name));
    

    that how i do it...

    public final static String APP_PATH_SD_CARD = "/DesiredSubfolderName/";
    public final static String APP_THUMBNAIL_PATH_SD_CARD = "thumbnails";
    
    public boolean saveImageToExternalStorage(Bitmap image) {
    String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + APP_PATH_SD_CARD + APP_THUMBNAIL_PATH_SD_CARD;
    
    try {
    File dir = new File(fullPath);
    if (!dir.exists()) {
    dir.mkdirs();
    }
    
    OutputStream fOut = null;
    File file = new File(fullPath, "desiredFilename.png");
    file.createNewFile();
    fOut = new FileOutputStream(file);
    
    // 100 means no compression, the lower you go, the stronger the compression
    image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    fOut.flush();
    fOut.close();
    
    MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());
    
    return true;
    
    } catch (Exception e) {
    Log.e("saveToExternalStorage()", e.getMessage());
    return false;
    }
    }
    
    0 讨论(0)
提交回复
热议问题