我想在用户捕获图像后执行操作。但是我在捕获图像后看到没有任何反应。我正在使用下面的代码和CWAC-Camera库。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;
}
}
答案 0 :(得分:0)
onPictureTaken()
,因为这不是库的工作方式。
该文档介绍了如何override photo saving并从相机接收byte[]
以执行您计划执行的任何操作。它涉及创建您自己的CameraHost
(无论是从头开始还是通过子类化SimpleCameraHost
)并覆盖saveImage(PictureTransaction, byte[])
。