Hi,
this sample open the camera, take the photo and get the image back as a Bitmap.
Using java Syntax Highlighting
package teste.camera;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.util.Log;
import android.widget.ImageView;
public class TesteIntent extends Activity {
private static final String CATEGORIA = "livro";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(i, 5);
} catch (Exception e) {
Log.e(CATEGORIA, e.getMessage());
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bundle extras = data.getExtras();
Bitmap b = (Bitmap) extras.get("data");
System.out.println(b.getWidth() + ", " + b.getHeight());
ImageView img = new ImageView(this);
img.setImageBitmap(b);
setContentView(img);
try {
FileOutputStream out = openFileOutput("camera.jpg", MODE_APPEND);
BufferedOutputStream bos = new BufferedOutputStream(out);
b.compress(Bitmap.CompressFormat.JPEG, 100, out);
bos.flush();
bos.close();
} catch (IOException ex) {
Log.e(CATEGORIA, ex.getMessage());
}
}
}
Parsed in 0.036 seconds, using
GeSHi 1.0.8.4
you can´t save in the drawable folder.. this sample save in /data/data/your_package/files