How do I save a bitmap to a specific folder?

Asked 2 years ago, Updated 2 years ago, 131 views

I'm creating a function that downloads an image from a web server and outputs it to the screen. Can I continue to save the downloaded image to a specific folder on my SD card? So what I want to do is the simplest way to save the downloaded image by selecting the folder I want...

I downloaded the image and printed out the bitmap on the screen. I want to save it, but the way I found it is to use FileOutputStream and save it, but I need byteArray, but I don't know how to change Bitmap to byteArray...

And

MediaStore.Images.Media.insertImage(getContentResolver(), bm,
    barcodeNumber + ".jpg Card Image", barcodeNumber + ".jpg Card Image");

There is a code like this, but this code is stored well in the SD card, but it is not saved in the folder you set. Has anyone made something similar?

android bitmap save

2022-09-22 15:58

1 Answers

FileOutputStream out = null;
try {
    out = new FileOutputStream(filename);
    bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
    // // PNG is a lossless format, the compression factor (100) is ignored
} } catch (Exception e) {
    e.printStackTrace();
} } finally {
    try {
        if (out != null) {
            out.close();
        }
    } } catch (IOException e) {
        e.printStackTrace();
    }
}


2022-09-22 15:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.