I want to perform an action after user has captured an image.But i see nothing happens after I captured an image.I am using below code and CWAC-Camera library.Content written inside onPictureTaken
is the action which i want to perform after user captured an image-
public class CameraActivity extends Activity implements Camera.PictureCallback {
private final String TAG_CAMERA_FRAGMENT = "camera_fragment";
private CameraPreview mCameraPreview;
ImageView switchToVideoOpen,camera;
private Boolean isVideoOpen = false;
CircleImageView togglePlay;
RelativeLayout actioncamera;
View blackTransparent;
byte[] datacamera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_camera);
switchToVideoOpen=(ImageView)findViewById(R.id.switchToVideoOpen);
camera=(ImageView)findViewById(R.id.camera);
togglePlay = (CircleImageView) findViewById(R.id.togglePlay);
actioncamera = (RelativeLayout) findViewById(R.id.audio_actions_container);
blackTransparent = findViewById(R.id.blacktreansparent);
CameraFragment f = new CameraFragment();
getFragmentManager().beginTransaction()
.add(R.id.preview_view, f, TAG_CAMERA_FRAGMENT)
.commit();
f.setHost(new SimpleCameraHost(this));
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
takePicture();
}
});
switchToVideoOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isVideoOpen) {
isVideoOpen = true;
switchToVideoOpen.setImageResource(R.drawable.video_stop);
camera.setImageResource(R.drawable.video_icon);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
takeVideo();
}
else{
isVideoOpen = false;
switchToVideoOpen.setImageResource(R.drawable.video_icon);
camera.setImageResource(R.drawable.video_stop);
stopVideo();
}
}
});
}
@Override
public void onResume() {
super.onResume();
}
private void takePicture() {
CameraFragment f = (CameraFragment) getFragmentManager().findFragmentByTag(TAG_CAMERA_FRAGMENT);
if (f != null && f.isVisible()) {
f.takePicture();
}
}
private void takeVideo() {
CameraFragment f = (CameraFragment) getFragmentManager().findFragmentByTag(TAG_CAMERA_FRAGMENT);
if (f != null && f.isVisible()) {
try {
f.record();
} catch (Exception e) {
}
}
}
private void stopVideo() {
CameraFragment f = (CameraFragment) getFragmentManager().findFragmentByTag(TAG_CAMERA_FRAGMENT);
if (f != null && f.isVisible()) {
try {
f.stopRecording();
} catch (Exception e) {
}
}
}
@Override
public void onPictureTaken(byte[] bytes, Camera camera) {
String pictureFile = GFileUtils.getGCameraDir().getAbsolutePath()+"/"+
G.getFileNameForGMedia(G.General.MEDIA_TYPE_PHOTO);
if (pictureFile == null) {
return;
}
blackTransparent.setVisibility(View.VISIBLE);
actioncamera.setVisibility(View.VISIBLE);
togglePlay.setVisibility(View.VISIBLE);
datacamera=bytes;
}
}
onPictureTaken()
will not be called, because that is not how the library works.The documentation covers how you can override photo saving and receive the
byte[]
from the camera for doing whatever it is that you plan on doing. It involves creating your ownCameraHost
(whether from scratch or by subclassingSimpleCameraHost
) and overridingsaveImage(PictureTransaction, byte[])
.