Aman Srivastava
Aman Srivastava

Reputation: 973

How to write bitmap into a file without bitmap.compress method

I don't want to use bitmap's compress method. I just want to write directly into sd card. Don't want to use compression in my case.

Upvotes: 3

Views: 1704

Answers (1)

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

Based on the title: This saves the URL directly to a file:

    FileOutputStream output = ctx.openFileOutput(localFileName, context.MODE_PRIVATE);

            URLConnection openConnection = new URL(url).openConnection();
            openConnection.connect();
            InputStream inputStream = openConnection.getInputStream();
            byte[] buffer = new byte[1024];
            for (int n = inputStream.read(buffer); n >= 0; n = inputStream.read(buffer))
                output.write(buffer, 0, n);
            output.flush();
            output.close();
            inputStream.close();

You can change openFileOutput for a new FileOutputStream(new File("filepath")) to store on SDCard

But you look like are having problem with the ImageLoader API.

Upvotes: 1

Related Questions