Closed Paul75 closed 7 years ago
Are you using camera v1 or v2?
I'm using the code that have in the source code.
2017-09-24 18:35 GMT+02:00 Dionysis Lorentzos notifications@github.com:
Are you using camera v1 or v2?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Fotoapparat/Fotoapparat/issues/101#issuecomment-331721951, or mute the thread https://github.com/notifications/unsubscribe-auth/AAb5ZvtnPoKR-IWRz-HHjnTIVDLCSOb2ks5sloTpgaJpZM4Ph8Mx .
-- Paul
Okay, in other words. How do initialize FA and when do you call .onStop()?
Hello,
I call ::
private FotoapparatSwitcher fotoapparatSwitcher;
private Fotoapparat frontFotoapparat;
cameraView = findViewById(R.id.camera_view);
private void setupFotoapparat() {
backFotoapparat = createFotoapparat(LensPosition.BACK);
fotoapparatSwitcher = FotoapparatSwitcher.withDefault(backFotoapparat);
}
@Override
protected void onStart() {
super.onStart();
if (hasCameraPermission) {
fotoapparatSwitcher.start();
}
}
@Override
protected void onStop() {
super.onStop();
if (hasCameraPermission) {
fotoapparatSwitcher.stop();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
Thanks, but could you please post the full relevant code? E.g. What is in the createFotoapparat
method? Also, is this happening on some specific device/API version? Thanks!
Hello,
API 24.
Code ::
`package fr.laposte.gompost.activity.photos;
import android.Manifest; import android.content.pm.PackageManager; import android.os.Environment; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.SwitchCompat; import android.view.View; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.SeekBar; import android.widget.Toast;
import java.io.File;
import fr.laposte.gompost.R; import io.fotoapparat.Fotoapparat; import io.fotoapparat.FotoapparatSwitcher; import io.fotoapparat.error.CameraErrorCallback; import io.fotoapparat.hardware.CameraException; import io.fotoapparat.parameter.LensPosition; import io.fotoapparat.parameter.ScaleType; import io.fotoapparat.parameter.update.UpdateRequest; import io.fotoapparat.photo.BitmapPhoto; import io.fotoapparat.preview.Frame; import io.fotoapparat.preview.FrameProcessor; import io.fotoapparat.result.PendingResult; import io.fotoapparat.result.PhotoResult; import io.fotoapparat.view.CameraView;
import static io.fotoapparat.log.Loggers.fileLogger; import static io.fotoapparat.log.Loggers.logcat; import static io.fotoapparat.log.Loggers.loggers; import static io.fotoapparat.parameter.selector.AspectRatioSelectors.standardRatio; import static io.fotoapparat.parameter.selector.FlashSelectors.autoFlash; import static io.fotoapparat.parameter.selector.FlashSelectors.autoRedEye; import static io.fotoapparat.parameter.selector.FlashSelectors.off; import static io.fotoapparat.parameter.selector.FlashSelectors.torch; import static io.fotoapparat.parameter.selector.FocusModeSelectors.autoFocus; import static io.fotoapparat.parameter.selector.FocusModeSelectors.continuousFocus; import static io.fotoapparat.parameter.selector.FocusModeSelectors.fixed; import static io.fotoapparat.parameter.selector.LensPositionSelectors.lensPosition; import static io.fotoapparat.parameter.selector.Selectors.firstAvailable; import static io.fotoapparat.parameter.selector.SizeSelectors.biggestSize; import static io.fotoapparat.result.transformer.SizeTransformers.scaled;
public class CameraActivity extends AppCompatActivity { private final PermissionsDelegate permissionsDelegate = new PermissionsDelegate(this); private boolean hasCameraPermission; private CameraView cameraView;
private FotoapparatSwitcher fotoapparatSwitcher;
private Fotoapparat frontFotoapparat;
private Fotoapparat backFotoapparat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
cameraView = findViewById(R.id.camera_view);
hasCameraPermission = permissionsDelegate.hasCameraPermission();
if (hasCameraPermission) {
cameraView.setVisibility(View.VISIBLE);
} else {
permissionsDelegate.requestCameraPermission();
}
setupFotoapparat();
takePictureOnClick();
//focusOnLongClick();
//switchCameraOnClick();
//toggleTorchOnSwitch();
}
private void setupFotoapparat() {
//frontFotoapparat = createFotoapparat(LensPosition.FRONT);
backFotoapparat = createFotoapparat(LensPosition.BACK);
fotoapparatSwitcher = FotoapparatSwitcher.withDefault(backFotoapparat);
}
/*private void toggleTorchOnSwitch() {
SwitchCompat torchSwitch = (SwitchCompat) findViewById(R.id.torchSwitch);
torchSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
fotoapparatSwitcher
.getCurrentFotoapparat()
.updateParameters(
UpdateRequest.builder()
.flash(
isChecked
? torch()
: off()
)
.build()
);
}
});
}*/
/*private void switchCameraOnClick() {
View switchCameraButton = findViewById(R.id.switchCamera);
switchCameraButton.setVisibility(
canSwitchCameras()
? View.VISIBLE
: View.GONE
);
switchCameraOnClick(switchCameraButton);
}*/
/*private void switchCameraOnClick(View view) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switchCamera();
}
});
}*/
/*private void focusOnLongClick() {
cameraView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
fotoapparatSwitcher.getCurrentFotoapparat().autoFocus();
return true;
}
});
}*/
private void takePictureOnClick() {
ImageView take = findViewById(R.id.take);
take.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
takePicture();
}
});
}
private boolean canSwitchCameras() {
return frontFotoapparat.isAvailable() == backFotoapparat.isAvailable();
}
private Fotoapparat createFotoapparat(LensPosition position) {
return Fotoapparat
.with(this)
.into(cameraView)
.previewScaleType(ScaleType.CENTER_CROP)
.photoSize(standardRatio(biggestSize()))
.lensPosition(lensPosition(position))
.focusMode(firstAvailable(
continuousFocus(),
autoFocus(),
fixed()
))
.flash(firstAvailable(
autoRedEye(),
autoFlash(),
torch(),
off()
))
.frameProcessor(new SampleFrameProcessor())
.logger(loggers(
logcat(),
fileLogger(this)
))
.cameraErrorCallback(new CameraErrorCallback() {
@Override
public void onError(CameraException e) {
Toast.makeText(CameraActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
})
.build();
}
private void takePicture() {
PhotoResult photoResult = fotoapparatSwitcher.getCurrentFotoapparat().takePicture();
File saveDir = null;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
// Only use external storage directory if permission is granted, otherwise cache directory is used by default
saveDir = new File(Environment.getExternalStorageDirectory(), "GOMPOST_Photos");
saveDir.mkdirs();
}
/*photoResult.saveToFile(new File(
getExternalFilesDir("photos"),
"photo.jpg"
));*/
photoResult.saveToFile(saveDir);
photoResult
.toBitmap(scaled(0.25f))
.whenAvailable(new PendingResult.Callback<BitmapPhoto>() {
@Override
public void onResult(BitmapPhoto result) {
ImageView imageView = (ImageView) findViewById(R.id.result);
imageView.setImageBitmap(result.bitmap);
imageView.setRotation(-result.rotationDegrees);
}
});
}
/*private void switchCamera() {
if (fotoapparatSwitcher.getCurrentFotoapparat() == frontFotoapparat) {
fotoapparatSwitcher.switchTo(backFotoapparat);
} else {
fotoapparatSwitcher.switchTo(frontFotoapparat);
}
}*/
@Override
protected void onStart() {
super.onStart();
if (hasCameraPermission) {
fotoapparatSwitcher.start();
}
}
@Override
protected void onStop() {
super.onStop();
if (hasCameraPermission) {
fotoapparatSwitcher.stop();
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (permissionsDelegate.resultGranted(requestCode, permissions, grantResults)) {
fotoapparatSwitcher.start();
cameraView.setVisibility(View.VISIBLE);
}
}
private class SampleFrameProcessor implements FrameProcessor {
@Override
public void processFrame(Frame frame) {
// Perform frame processing, if needed
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
} `
I can't say what is the exact reason for that, but I can say that this is a normal behaviour which is present in other camera libraries as well. It does not affect the app in any harmful way.
Hello,
The message in console is :
09-24 18:20:48.055 8021-8036/fr.laposte.gompost E/BufferQueueProducer: [SurfaceTexture-0-8021-0] dequeueBuffer: BufferQueue has been abandoned 09-24 18:20:48.063 8021-8034/fr.laposte.gompost E/BufferQueueProducer: [SurfaceTexture-0-8021-0] queueBuffer: BufferQueue has been abandoned 09-24 18:20:48.096 8021-8036/fr.laposte.gompost E/BufferQueueProducer: [SurfaceTexture-0-8021-0] queueBuffer: BufferQueue has been abandoned 09-24 18:20:48.130 8021-8034/fr.laposte.gompost E/BufferQueueProducer: [SurfaceTexture-0-8021-0] queueBuffer: BufferQueue has been abandoned 09-24 18:20:48.163 8021-8446/fr.laposte.gompost E/BufferQueueProducer: [SurfaceTexture-0-8021-0] queueBuffer: BufferQueue has been abandoned
when I do a onBackPressed.
Normal ?