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
the
sdcard - but the image length written is 0. Any ideas as to why this
occurs?

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

Thanks

-- 



Re: Saving an image

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


 Hi,
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())

        tmpDir.mkdirs();

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

      BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(file));

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

      out.flush();

      out.close();

      //bitmap.recycle();

      return true;

    } catch (IOException e) {

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

      return false;

    }

  }

2011/5/20 kypriakos <demet...@ece.neu.edu>

-- 


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:

FrameLayout->TextSwitcher->TextViews

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

Any pointers appreciated!

Regards,
Leif

-- 

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.

http://developer.android.com/reference/android/provider/Settings.html

--------------------------------------------------------------------------------------------------------------
Intent intentSettings = new Intent();
intentSettings.setAction(Settings.ACTION_DATA_ROAMING_SETTINGS);
cont.startActivity(intentSettings);
---------------------------------------------------------------------------------------------------------------


Thanks

-- 

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 BigClasses.com