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. Can I use the Linux usbserial driver and ADB at the same time?

I was trying to connect to the serial port on the Android device from
the host PC. What I was doing was loading the "usbserial" driver:

modprobe usbserial product=<product id> vendor=<vendor id>

It seems it does recognize all serial functions in the USB and created
several ttyUSB ports/devices. However, it seems (at least on my
device) that the interface used by ADB is also picked up by
"usbserial", and because of that, I couldn't use ADB to connect to the
device until I unload usbserial.

Do you know if this is an issue? Is there a way to get both usbserial
and ADB to work?

Thanks!

-- 
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: 

2. building source code.

i downloaded the source and ran make. im getting error, could you let
me know what im missing?

cmki...@laptop:~/mydroid$ make
============================================
PLATFORM_VERSION_CODENAME=AOSP
PLATFORM_VERSION=AOSP
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=OPENMASTER
============================================
Install: out/host/linux-x86/framework/apicheck.jar
Install: out/host/linux-x86/framework/clearsilver.jar
Install: out/host/linux-x86/framework/droiddoc.jar
host SharedLib: libneo_util (out/host/linux-x86/obj/lib/
libneo_util.so)
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.4.1/
libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.4.1/
libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.4.1/
libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.4.1/
libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/lib/libneo_util.so] Error 1

-- 
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: 

3. adding a new package to the android filesystem

4. Android and Kernel 2.6.33

5. Application that works on WAP connection

6. Motorola Droid - QCIF Camera Preview and Capture

7. GPS accuracy reliability