0

Possible Duplicate:
Capture Image from Camera and Display in Activity

I`m new in android programation and I´m having a problem with some stuff. I have an ImageView Without any image loaded, when I take a photo with the camera, the captured image puts into the ImageView. I want to save this, but I dont know how to save the directory of the photo in a string, and how to load this directory in the imageView at the "onCreate".

I know that this is a noob cuestion, but this is my first time with this stuff.

Thanks

Community
  • 1
  • 1
  • http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – user1378730 May 15 '12 at 09:26
  • is saving image is need or you just want to save to show in activity because when you use capture image you can get in result back in activity like as http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – Dheeresh Singh May 15 '12 at 09:27

2 Answers2

0

This code will get your ImageView as a Bitmap

ImageView imgView = (ImageView) findViewById(R.id.myImageView);
imgView.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(imgView.getDrawingCache());

File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/your_app_package/image.png");

This code will save it to a file

try {
       FileOutputStream out = new FileOutputStream(cachePath);
       bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
       e.printStackTrace();
}
Rawkode
  • 21,990
  • 5
  • 38
  • 45
  • Thanks a lot, this help me in what I`m trying to do. Now Im trying to put this image in the imageview when I load the application, I save the string in the sharedpreferences, but I dont know how to become this string into a useful resource for this stuff, can i ask you a little bit more help please? thanks – BattleCroissant May 15 '12 at 10:30
  • Excellent. Please remember to select this as the answer :-) – Rawkode May 15 '12 at 10:31
0

I doing something like this:

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
picture.compress(Bitmap.CompressFormat.JPEG, 80, bytes);


File f = new File(Environment.getExternalStorageDirectory() + File.separator + picId + ".jpg");
FileOutputStream fo = null;
try 
{
    f.createNewFile();
    fo = new FileOutputStream(f);
} 
catch (IOException e) 
{
    e.printStackTrace();
}
catch (FileNotFoundException e) 
{
    e.printStackTrace();
}


try 
{
    fo.write(bytes.toByteArray());
} 
catch (IOException e) 
{
    e.printStackTrace();
}

...where picId is name for a file.

goodm
  • 7,275
  • 6
  • 31
  • 55