Saving an image

by kypriakos » Fri, 20 May 2011 13:35:49 GMT

Sponsored Links
 HI all,

I use the               mCamera.takePicture(null, null, jpegCallback); to snap
a picture through an activity. When the callback occurs I do see the
data (approx 1.5 MB in length) and I use the following to write it to
sdcard - but the image length written is 0. Any ideas as to why this

            String path =
            OutputStream out = null;
            File file = new File(path, "IMAGE.jpg");
            out = new FileOutputStream(file);
            System.out.println("Wrote image to =["+path+"]");



Re: Saving an image

by Francisco Dalla Rosa soares » Fri, 20 May 2011 14:27:26 GMT

I had the same problem and it seems that you have to compress the
image before saving it t the disk.
And I think you also have to flush the OutputStream.

This is how I'm doing it. Hope it helps you:

 public boolean storeImage(Bitmap bitmap, int picId) {

    try {

      File baseDir = Environment.getExternalStorageDirectory();

      File tmpDir = new File(baseDir, APP_BASE_DIR + APP_CACHE_DIR);

      if (!tmpDir.exists())


      File file = new File(tmpDir,String.valueOf(picId));

      BufferedOutputStream out = new BufferedOutputStream(new

      bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);




      return true;

    } catch (IOException e) {

      e.printStackTrace(); // TODO: Customize this generated block

      return false;



2011/5/20 kypriakos <>


Sponsored Links

Other Threads

1. New Market FeatuCounts of ratings

I just noticed a new feature in the market comments section. Now you
have the counts of the star ratings, exact counts so we can really
figure our ratings to a fine degree. For instance, I now know my app
"Radar Now!" has precisely a rating of 4.3206456

Way cool!

-John Coryat


2. Copy protection getting deprecated

I just pushed an update on one of my apps and noticed a little red line
stating that copy protection will be deprecated soon.  What I didn't see was
any mention of what that will mean for us who are currently using it.  I'd
love to easily turn that off without the affect on my current users.  I must
say, I'm quite nervous about how this will get handled for existing apps
using copy protection.

Has anyone seen this already and maybe I missed the conversation?

Chris Stewart

Android app for MFL fantasy football owners
Fantasy Football
Android app for all fantasy football fanatics
Social Updater<>-
An easy way to send your status blast to multiple social networks


3. continue loading WebView on screen off/ application switch

4. Command line build error: 'Unable to get buffer of resource asset file'

5. Bitmap mutability dependent on location

6. USB Issues: 2nd Droid not recognized by ADB

7. Scrolling like a spreadsheet