我还是开发新手,我想知道是否有人可以在我的情况下引导我朝着正确的方向前进,因为我不确定从哪里开始:
方案:
按 acapture_button
捕获图像(capture_button
并且imagePreview
处于同一活动中)后,我想删除capture_button
并有一个ACCEPT
或DECLINE
按钮。这些按钮应该是accept
图像然后保存,或者decline
图像并返回图像预览。
现在,我不确定是否应该在capture_button
按下时创建另一个活动,
PhotoActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
mCamera = getCameraInstant();
mCameraPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(id.camera_preview);
preview.addView(mCameraPreview);
// Add a listener to the Capture button
Button captureButton = (Button) findViewById(id.button_capture);
captureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// get an image from the camera
mCamera.takePicture(null, null, mPicture);
}
}
);
}
PictureCallback mPicture = new PictureCallback(){
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.e("photo","pictureCallback");
// TODO Auto-generated method stub
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if(pictureFile==null){
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e){
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
};
private File getOutputMediaFile(int type){
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "Photo");
if (!mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
Log.d("Photo", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");
return mediaFile;
}
现在,我应该Intent
在capture_button
点击后做某种事情,还是在
PictureCallback mPicture = new PictureCallback(){
然后onPictureTaken
参加其他活动?还是我的想法全错了?
请帮忙?
先感谢您。