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. Why I get wrong hardware screen resolution.

Hi,

I use the flowing code to get the screen resolution:

        Display display = getWindowManager().getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);

Then as I known:
dm.heightPixels  is  The absolute height of the display in pixels.
dm.widthPixels   is  The absolute width of the display in pixels.

But when I run this code on a hardware which resolution is 800x480 and
on the emulator which is WVGA800 with "Abstracted LCD density" 160. I
got dm.widthPixels 320 and dm.heightPixels 480.

Why I get this "wrong" width and height? Is this the hardware screen
resolution? If something I misunderstood, how could I get the real
size of my screen.

Thanks for help!

-- 

2. Finding Specific Installed Applications at Run Time




Package name is better but see the below note.


Let user pick up which application is i.e. "Calendar" one on their
device. There's so many replacements around and poeople are really
using them so you are quite not able to know them all. Your test will
fail for a group users no matter of how you test its presence or you
detect the wrong one than user really uses.

-- 
Regards,
Marcin

-- 

3. Honeycomb + landscape + Mac = will not stay in landscape

4. phone keypad intent?

5. Activity without UI

6. Touch Screen Scrolling is not working on android-2.3

7. "Send via..."-integration?