Bitmap bmToSave = ... // the bitmap you want to save
int height = ... // height of bitmap
int width  = ... // width of bitmap

int[] bmData = new int[TMP_BUFFER_SIZE]; // holds the ARGB data for
pixels of bmToSave
int heightChunk = ... // number of pixel-rows of bmToSave that will
fit into the buffer of bmData

IntArrayOutputStream ios = null;
try {
        final OutputStream os = new FileOutputStream(getTemporarySaveFile());
        ios = new IntArrayOutputStream(os);
        int heightLeft = height;
        int y = 0;
        while (heightLeft > 0) {
                final int chunkSize = Math.min(heightChunk, heightLeft);

                bmToSave.getPixels(bmData, 0, width, 0, y, width, chunkSize);
                ios.write(bmData, 0, width*chunkSize);

                y += chunkSize;
                heightLeft -= heightChunk;
        }
}
catch (Exception e) {
        throw new RuntimeException(e);
}
finally {
        if (ios != null) { try { ios.close(); } catch (Exception e) {} }
}


Notes:
-- The getTemporarySaveFile() will make sure that a file on the SD-
card exists that can be used to save the bitmap to.
-- The IntArrayOutputStream class is a class that i wrote: It
translates an integer-array into a proper byte-array (one integer -->
4 bytes). There is a corresponding IntArrayInputStream to read integer-
arrays.
-- Above code may not compile. It only serves as an guideline. The
actual code is different, because that code does not save a bitmap 'as
is', but a bitmap backed by a canvas that allows me to save color-
corrections on the original bitmap.


On Aug 23, 2:32 pm, karthikr <[email protected]> wrote:
> I am trying to write the contents of thebitmapwithout doing a
> compress on it for a format, as I am facing somme problems in quality
> while formatting.
>
> I am using thte below code but its not working,
>
> ByteBuffer bf = ByteBuffer.allocate(IMAGE_WIDTH*IMAGE_HEIGHT*4);
> mBitmap.copyPixelsToBuffer(bf);
> out.write(bf.array());
>
> Is there any other way forward,can i do a get pixels and write it to
> an output stream?
>
> If i can any sample code or pointers for the same?
>
> Thanks in advance,
> R.Karthik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to