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. Inside WebView class addJavaScriptInterface() method is calling in reverse order when I have two calling stmts.

I'm wondering
 > webview.addJavascriptInterface(new Def(), "Abc.Def");
 does work or not.
Actually, I need it too.
like,
{{
window.Abc.Def.method();
}} on script.

How can I add javascriptinterface on deeper inner object? not as a
directly child of window object.

Sorry that it's not an answer of yours.
-19




-- 

2. PowerManagement - wakelocks

Hi ,

PARTIAL_WAKE_LOCK
SCREEN_DIM_WAKE_LOCK
SCREEN_BRIGHT_WAKE_LOCK
FULL_WAKE_LOCK

In the above 4 wakelocks , only the PARTIAL_WAKE_LOCK  is calling
wakelock.c kernel API. How the other 3 wakelocks are handled
internally?

The other 3 wakelocks calling android_os_power.app -->
setScreenState(boolean).But its only make the sceen on/off
how the DIM/BRIGHT is handled?How its related to wakelock?

-- 

3. HTML5 future on Android Webkit

4. Can you participate our survey?

5. Sending and receiving.

6. build.properties being ignored?

7. eclipse closes on opening main.xml file