简体   繁体   English

用户捕获图像后执行操作

[英]Performing an action after user has captured an image

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- 我想在用户捕获图像后执行一个动作。但是我捕获图像后什么也没看到。我正在使用下面的代码和CWAC-CameraonPictureTaken里面写的onPictureTaken是用户捕获后想要执行的动作一个图像-

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. onPictureTaken()将不会被调用,因为这不是库的工作方式。

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. 该文档介绍了如何覆盖照片保存方式以及如何从相机接收byte[]来完成您计划要做的任何事情。 It involves creating your own CameraHost (whether from scratch or by subclassing SimpleCameraHost ) and overriding saveImage(PictureTransaction, byte[]) . 它涉及创建您自己的CameraHost (无论是从头开始还是通过子类化SimpleCameraHost )并覆盖saveImage(PictureTransaction, byte[])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android执行动作后PendingIntent会死吗? - Android does PendingIntent die after performing action? 片段事务动画完成后执行操作 - Performing action after fragment transaction animation is finished 在Android中裁剪后,捕获的图像错误地拉伸 - Captured image stretches wrongly after cropping in Android 执行操作后,如何延迟启动新操作? - After performing an action,how to delay the starting of a new action? 在Android中单击操作后如何从通知发送Toast? - How to send a Toast from a Notification after performing an action on click in Android? 在Android中使用Surfaceview类捕获后如何在imageview中显示图像 - how to display image in imageview after captured using surfaceview class in android 捕获单个图像后释放相机实例并返回父活动 - Releasing camera instance after a single image is captured and returning to parent activity 使用相机android捕获图像后应用程序崩溃 - Application crashed after captured image using camera android 捕获图像后调用StartPreview()的最佳方法是什么? - What's the best way to call StartPreview() after an image is captured? 从特定日期/时间后捕获的android画廊中删除图像 - Delete image from android gallery captured after particular date/time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM