Save bitmap to location

前端 未结 19 2305
悲哀的现实
悲哀的现实 2020-11-22 00:20

I am working on a function to download an image from a web server, display it on the screen, and if the user wishes to keep the image, save it on the SD card in a certain fo

相关标签:
19条回答
  • 2020-11-22 01:07

    You want to save Bitmap to Directory of your Choice. I have made a library ImageWorker that enables the user to load, save and convert bitmaps/drawables/base64 images.

    Min SDK - 14

    Pre-requisite

    • Saving files would require WRITE_EXTERNAL_STORAGE permission.
    • Retrieving files would require READ_EXTERNAL_STORAGE permission.

    Saving Bitmap/Drawable/Base64

    ImageWorker.to(context).
        directory("ImageWorker").
        subDirectory("SubDirectory").
        setFileName("Image").
        withExtension(Extension.PNG).
        save(sourceBitmap,85)
    

    Loading Bitmap

    val bitmap: Bitmap? = ImageWorker.from(context).
        directory("ImageWorker").
        subDirectory("SubDirectory").
        setFileName("Image").
        withExtension(Extension.PNG).
        load()
    

    Implementation

    Add Dependencies

    In Project Level Gradle

    allprojects {
            repositories {
                ...
                maven { url 'https://jitpack.io' }
            }
        }
    

    In Application Level Gradle

    dependencies {
                implementation 'com.github.ihimanshurawat:ImageWorker:0.51'
        }
    

    You can read more on https://github.com/ihimanshurawat/ImageWorker/blob/master/README.md

    0 讨论(0)
提交回复
热议问题