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. receive GPS enable/disable settings event


I need to receive the event on GPS enable/disable status. Example -
user goes to Settings/Security and location and press "enable GPS
satellites" checkbox - my application should receive some event at
this moment.

I did try to subscribe Intent.ACTION_PROVIDER_CHANGED and
Intent.ACTION_CONFIGURATION_CHANGED but none of those worked. Did not
find any other similar broadcast intents to subscribe to.

LocationListener looks to be ok as it has onProviderDisabled and
onProviderEnabled methods, but I can register it only with
requestLocationUpdates(String provider, long minTime, float
minDistance, LocationListener listener) which would mean receiving
periodical updates for location change events which are not needed in
my app and would just eat battery.


2. Are the gyroscope features broken in Android 2.3 or Nexus S?

I tried the gyroscope features a bit when I got the Nexus S, but
couldn't find any way to make it more accurate than what can already
be done with the accelerometer and magnetometer.

Since then I've been waiting for someone else to do something, but
haven't found any apps that demonstrate the gyroscope in any
convincing way and there doesn't seem to be much discussion about gyro
in this google group or elsewhere.

Have I missed something, is it broken or is it just a feature that
nobody wants to use?


3. 2 Android GPS development issues

4. What is the format of RTSP streaming response in Android ?

5. Problem stripping Log calls with ProGuard

6. Location Change Triggering for Network but not for GPS

7. Anything wrong with this view?