我想创建一个简单的应用程序,我可以拍照并传递这张照片,然后关闭相机并将此照片传递给另一个活动。我不知道怎么开始。你能举一些例子我怎么能这么简单地做到这一点?
答案 0 :(得分:0)
捕获图像: int CAMERA_REQUEST = 1888;
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("putSomething", true);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
通过onActivityResult获取照片:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
this.photo = (Bitmap) data.getExtras().get("data");
}
}
您可以通过将照片转换为字节数组并传递意图来传递照片
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image = stream.toByteArray();
Intent intent = new Intent(this, YourActivity.class);
intent.putExtra("photo", image);
startActivity(intent);