I need to send an image taken from the Camera over network. The image is too large to create a bitmap needed to use bitmap.compress(); It looks like the Gmail application can attach images from the camera while maintaining their large pixel size but with a great reduction their file size.
This won’t work because I getBitmap() will return an Image to large to allocate and I don’t want to sub sample it down to a smaller size.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
getBitmap().compress(Bitmap.CompressFormat.JPEG, 70, baos);
Any ideas on how I can do the same without exceeding my total memory?
Update:
For anyone coming back to this thread I followed Phil’s answer and used Apache MultiPartEntity to get the job done easily. (It handles streaming files from disk to network for you) http://hc.apache.org/httpcomponents-client-ga/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntity.html
As you haven’t defined quite what ‘send over the network’ means here, it’s difficult to give specific advice.
However, if you want to send a lossless image (or with less loss than has already occurred), I don’t think you’ll be able to compress much more, as JPEG already compresses. It uses lossy compression, so if you increase the JPEG compression, you lose details (although maybe not ones you’d notice, as it’s based on frequencies not pixels)
If you just need to send over the network, then why not just open an InputStream, and spool data directly to the network?
Hope this helps – if you can provide more details, I’ll update the answer.
Best wishes,
Phil Lello