[android-developers] How do I can take a photo in Android and show it in an ImageView?
I tried this code, but it didn't do anything, with my phone:
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class camera_surface extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.camera_surface);
Button scan_it = (Button)
findViewById(R.id.camera_button);
scan_it.setOnClickListener(new View.OnClickListener() {
FrameLayout fl = (FrameLayout)
findViewById(R.id.preview);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
takePicture();
}
private void takePicture() {
// TODO Auto-generated method stub
Camera camera = Camera.open();
Camera.Parameters parameters =
camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
camera.takePicture(null, rawCallback, null);
camera.release();
}
PictureCallback rawCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera
camera) {
// TODO Do something with the image RAW data.
byte[] picture;
picture = data;
Bitmap pic = BitmapFactory.decodeByteArray(data,
0, data.length);
Canvas c = new Canvas(pic);
fl.draw(c);
}
};
});
}
}
Thanks for any reply,
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home