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. TextSwitcher and/or TranslateAnimation changed in API level 8 and upwards?

I am using a TextSwitcher and a TranslateAnimation to create a
slotmachine reel effect.

It works fine on API levels 4 through 7, but on API levels 8 and 9 it
breaks down for some reason.

Any clues as to why this is happening?

The UI structure is like this:


Any known changes in TextSwitcher, TextView or TranslateAnimation
since API level 7?

Any pointers appreciated!



2. No Activity found to handle Intent for ACTION_DATA_ROAMING_SETTINGS

Hi everyone,

Can anyone verify if this is some kind of a documentation error?
ACTION_DATA_ROAMING_SETTINGS seems to appear on the documentation but
it gives in error when I tried to invoke this menu.

Intent intentSettings = new Intent();



3. how to include resource files in a static java library?

4. Show Application Version Number with .apk file

5. Game pretty much like mine

6. Prevent an Android Service from getting destroyed after an unbind

7. DataStage Interactive Online Training at