Best way to save images which comes from server in android

后端 未结 3 827
甜味超标
甜味超标 2021-01-14 11:27

I am working on one application and getting product images from the server. Currently I am saving those images into the SQLite database after converting them into byte a

3条回答
  •  执笔经年
    2021-01-14 11:48

    Save them as a file on the external storage:

    File downloadDir = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyAppName/MyImages");
    if(!downloadDir.exists()){
       downloadDir.mkdirs();
    }
    

    will create a directory to store the pictures in.

    Then check out this guide here how to load only the right amount of pixels for your Image. Else you will get an OutOfMemory exception. (5MP picture will take up to 20MB of the heap)

提交回复
热议问题