gpt4 book ai didi

android - 来自 cwac-camera 的回调

转载 作者:搜寻专家 更新时间:2023-11-01 08:44:54 24 4
gpt4 key购买 nike

我正在尝试实现出色的库 cwac-camera。怎么实现图片的回调,怎么设置图片的路径,我好像想不通。

这是我的 CustomCameraFragment公共(public)类 CustomCameraFragment 扩展 CameraFragment { private static final String KEY_USE_FFC = "com.commonsware.cwac.camera.demo.USE_FFC";

public static CustomCameraFragment newInstance(boolean useFFC) {
CustomCameraFragment f = new CustomCameraFragment();
Bundle args = new Bundle();

args.putBoolean(KEY_USE_FFC, useFFC);
f.setArguments(args);
return (f);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SimpleCameraHost.Builder builder =
new SimpleCameraHost.Builder(new DemoCameraHost(getActivity()));
builder.useFullBleedPreview(true);
setHost(builder.build());
//setHost(builder.useFullBleedPreview(true).build());
}

public class DemoCameraHost extends SimpleCameraHost {
public DemoCameraHost(Context _ctxt) {
super(_ctxt);
}

@Override
public boolean useFrontFacingCamera() {
if (getArguments() == null) {
return (false);
}

return (getArguments().getBoolean(KEY_USE_FFC));
}

@Override
public boolean useSingleShotMode() {
return true;
}

@Override
public void onCameraFail(CameraHost.FailureReason reason) {
super.onCameraFail(reason);

Toast.makeText(getActivity(),
"Sorry, but you cannot use the camera now!",
Toast.LENGTH_LONG).show();
}

@Override
public void saveImage(PictureTransaction xact, Bitmap bitmap) {
super.saveImage(xact, bitmap);
}
}

我在另一个 fragment 的框架布局中使用它,但我无法弄清楚回调的正确实现。

我使用 CustomCameraFragment 的 fragment :我有一个拍照按钮:@OnClick(R.id.btnTakePicture) public void takePicture(查看 View ){

    try {
CustomCameraFragment.DemoCameraHost demoCameraHost = customCameraFragment.demoCameraHost;
PictureTransaction pictureTransaction = new PictureTransaction(demoCameraHost);
pictureTransaction.needBitmap(true);
customCameraFragment.takePicture(pictureTransaction);

} catch (Exception e) {
e.printStackTrace();
}

showCameraPreview(false);

}

但是在这个 fragment 中我需要:- 回调以了解照片的拍摄时间- 当触发回调时,我需要显示位图,而不是预览- 我需要能够设置保存图片的路径和文件名

我不清楚这 3 件事。

最佳答案

您必须覆盖 saveImage(PictureTransaction, byte[]) 函数,有关更多信息,请参见此处:

https://github.com/commonsguy/cwac-camera#overriding-photo-saving

关于android - 来自 cwac-camera 的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29412897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com