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. Method to detect a widget is visible - or otherwise in the foreground or background?

It would appear on a G1 (with the latest software update) that onUpdate
() runs even when the widget is not visible. Is there a way of sensing
that the widget is or is not visible or is otherwise in foreground?
That is, running the code below shows a logcat message at whatever
interval the Widget is scheduled to update, whether it's in foreground
or not, whether even the screen is dim or otherwise in deep sleep.

It would seem onUpdate should only be scheduled to run when the Widget
is in the foreground or visible. Is this a defect in the G1, or is
there some other API call to detect if the Widget is visible?


public class HomeScreenWidget extends AppWidgetProvider {

        public static final String TAG = "HomeScreenWidget";


       @Override
       public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds) {

                Log.i(TAG, "onUpdate - runs every 6 seconds on G1 - per the
updatePeriodMillis, even when not visible");
       }

}


<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/
android"
            android:minWidth="146dip"
            android:minHeight="146dip"
            android:updatePeriodMillis="6000"
            android:initialLayout="@layout/a_widget_home_screen"
         />


--~--~---------~--~----~------------~-------~--~----~

2. Notification and NotificationManager

Is it possible, without modifying the Android source, to query the
system for all current and pending notifications (system wide)?

Thanks.

--~--~---------~--~----~------------~-------~--~----~

3. persistent saveCacheFile in webview?

4. notifydatasetchanged in a ListView and handle Event click

5. Capture key pressed

6. left handed user

7. Input method for decimal numbers