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. To display the soft keyboard during the launch itself


2. service that maintains TTS

I have an application that relies on TTS to work in real time upon
device events (such as new message\sms).
To do that i start my service on device init and when i start it i
start the TTS engine.
Once started my broadcast receivers sends it IPC's to play whatever is
Of course if an ipc is sent to the service and it's not on i'll have o
start it again, acquire the TTS again and pay the performance penalty
that the sound will be played only seconds after the event.

My question is, is there a better way to handle the TTS engine ? if i
keep the TTS engine instance will it prevent other apps from using
it ? if from a moment that event has occurred i need about 0-200 milli
response, is there a solution other then a service that keeps a live
instance of TTS engine that is already initialized ?

10x! ^^


3. Butuh saran, beli android yg mana ya?

4. mending galaxy spica atau x10 mini?

5. Miring di Springhill pkl. 17:00 Wib

6. Jakarta Trans v0.1

7. Creating a listview in for an android home screen widgets