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. How to edit or modify pdf files in android?

Hello Friends,
I am developing one application and in this application i want
following things:
1.How to open pdf file in application?
2. How to add some text in pdf.?
3. How to edit or modify pdf files?

This all things i want to do using with my android application?

If it is possible in android can you please provide me some sample
code. It's Urgent.

Thank You


2. Android listView fade in Animation


I have a problem.

I want use a fade in animation on list view elements.

When I press a button, elems should fade in.
Unfortunatly it doesn't work the first time i Click, but works great
the others times

My button works like a toggle.

At launch :

adapter creation with elems INVISIBLE
nothing change
creation of a new adapter with elems INVISIBLE
fadein works fine
creation of a new adapter with elems INVISIBLE
fadein works fine

As you can see it's not the adapter the problem, because it's a new
each time I start animations, but they only works the 2second time and

Any ideas ?


3. ratingBar - strange problem

4. Bad link for "Using the Contacts API" article

5. C2DM Push not reaching device

6. OnTouchListener - repeat action on hold

7. Need a small tablet platform that runs Android OS.