在用户拍摄图像后执行操作
Performing an action after user has captured an image
我想在用户捕获 image.But 后执行操作 我在捕获 image.I 后没有任何反应 我正在使用下面的代码 CWAC-Camera library.Content 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()
不会被调用,因为这不是库的工作方式。
该文档介绍了如何 override photo saving 和从相机接收 byte[]
以执行您计划执行的任何操作。它涉及创建您自己的 CameraHost
(无论是从头开始还是通过继承 SimpleCameraHost
)和覆盖 saveImage(PictureTransaction, byte[])
.
我想在用户捕获 image.But 后执行操作 我在捕获 image.I 后没有任何反应 我正在使用下面的代码 CWAC-Camera library.Content 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()
不会被调用,因为这不是库的工作方式。
该文档介绍了如何 override photo saving 和从相机接收 byte[]
以执行您计划执行的任何操作。它涉及创建您自己的 CameraHost
(无论是从头开始还是通过继承 SimpleCameraHost
)和覆盖 saveImage(PictureTransaction, byte[])
.