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. how to remove a notification with flag FLAG_NO_CLEAR

as title.

thank you.

-- 

2. Android Emulator don't show up (Linux Fedora 12 x86_64)

I hopefully found a workaround
see: http://forums.fedoraforum.org/showthread.php?p=1350997&posted=1#post1350997

That's weird but audio is involved is this issue, arguments must
passed in the run configuration to disable audio:

In Eclipse, "Run" > "Run Configuration" > "Android Application" > "my
android app" tab > "target tab > "Additionnal Emulator Command Line
Options" type "-no-audio" + "Apply"

Running the application is now a success:

[2010-04-14 22:16:36 - HelloDroid] Android Launch!
[2010-04-14 22:16:36 - HelloDroid] adb is running normally.
[2010-04-14 22:16:36 - HelloDroid] Performing
com.tests.HelloDroid.HelloDroid activity launch
[2010-04-14 22:16:36 - HelloDroid] Automatic Target Mode: launching
new emulator with compatible AVD 'FakePhone_2_1'
[2010-04-14 22:16:36 - HelloDroid] Launching a new emulator with
Virtual Device 'FakePhone_2_1'
[2010-04-14 22:16:37 - HelloDroid] New emulator found: emulator-5554
[2010-04-14 22:16:37 - HelloDroid] Waiting for HOME
('android.process.acore') to be launched...
[2010-04-14 22:17:32 - HelloDroid] WARNING: Application does not
specify an API level requirement!
[2010-04-14 22:17:32 - HelloDroid] Device API version is 7 (Android
2.1)
[2010-04-14 22:17:32 - HelloDroid] HOME is up on device
'emulator-5554'
[2010-04-14 22:17:32 - HelloDroid] Uploading HelloDroid.apk onto
device 'emulator-5554'
[2010-04-14 22:17:32 - HelloDroid] Installing HelloDroid.apk...
[2010-04-14 22:17:45 - HelloDroid] Success!
[2010-04-14 22:17:45 - HelloDroid] Starting activity
com.tests.HelloDroid.HelloDroid on device
[2010-04-14 22:17:58 - HelloDroid] ActivityManager: Starting: Intent
{ act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.tests.HelloDroid/.HelloDroid }





-- 

3. about late resume, when PowerManagerService write on to /sys/power/state to call late resume

4. How often does an activity run?

5. playing YUV files from generated by the PVplayer test

6. Problem with insertion into SqLite Database..

7. Beginner Question: Is it possible to put each class into it's own java file in Eclispe?