Мне нужно открыть камеру при нажатии кнопки, мне нужно, когда я нажимаю кнопку, а затем камера открыта, и после нажатия на фотосъемку мне также нужно открыть переднюю камеру. Пожалуйста, помогите мне.Как открыть переднюю пользовательскую камеру?
Изображение Отозвать Код:
PictureCallback jpegCallback = new PictureCallback() {
@SuppressWarnings("deprecation")
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
String filepath = Environment.getExternalStorageDirectory().getPath();
Calendar c = Calendar.getInstance();
File videoDirectory = new File(filepath,"Spooks");
if (!videoDirectory.exists()) {
videoDirectory.mkdirs();
}
try {
Calendar _cal = Calendar.getInstance();
long _timeStamp = _cal.getTimeInMillis();
////System.out.println("Time stamp"+_timeStamp);
String fileToSend = videoDirectory.getAbsolutePath() + "/" +"Image_"+ _timeStamp +".png";
// Write to SD Card
System.out.println("Write to SD Card");
outStream = new FileOutputStream(fileToSend);
outStream.write(data);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Bitmap realImage;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 5;
options.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
options.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
realImage = BitmapFactory.decodeByteArray(data,0,data.length,options);
ExifInterface exif = null;
try {
exif = new ExifInterface(path + c.getTime().getSeconds()
+ ".jpg");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Log.d("EXIF value",
exif.getAttribute(ExifInterface.TAG_ORIENTATION));
if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
.equalsIgnoreCase("1")) {
realImage = rotate(realImage, 90);
} else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
.equalsIgnoreCase("8")) {
realImage = rotate(realImage, 90);
} else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
.equalsIgnoreCase("3")) {
realImage = rotate(realImage, 90);
} else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
.equalsIgnoreCase("0")) {
realImage = rotate(realImage, 90);
}
} catch (Exception e) {
}
camera.startPreview();
// camera.stopPreview();
System.out.println("Back cam image saved");
System.out.println("surfaceDestroyed on activity");
/*_camera.stopPreview();
_camera.release();*/
// finish();
// _camera.release();
// _camera.stopPreview();
//need to open from camera
_camera.release();
_camera = null;
if(_camera==null){
_camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
_camera.startPreview();
_camera.setErrorCallback(new ErrorCallback() {
public void onError(int error, Camera mcamera) {
_camera.release();
_camera = Camera.open();
Log.d("Camera died", "error camera");
}
});
}
if (_camera != null) {
if (Build.VERSION.SDK_INT >= 14)
setCameraDisplayOrientation(context,
CameraInfo.CAMERA_FACING_FRONT, _camera);
preview.setCamera(_camera);
}
}
};
Вы имеете в виду, как только камера заднего вида фотографирует, вы хотите открыть переднюю камеру? – Praveen
Вместо того, чтобы использовать намерения, чтобы открыть камеру, вы решили вместо этого создать пользовательскую переднюю + заднюю камеру? См. Http://developer.android.com/guide/topics/media/camera.html. В разделе «Создание приложения для камеры». Также см. Http://developer.android.com/reference/android/hardware/camera2/package-summary.html для более новой камеры API – Lunchbox
@Praveen да, это именно то, что я ищу. –