我正在制作一个相机应用程序,基本上我希望用户拍摄的图像在返回相机模式之前显示 5 秒钟。
此代码使其显示预览。但是我应该在它后面写什么才能让它停留五秒钟呢? 谢谢!!
@Override
public void onPictureTaken(byte[] data, Camera camera) {
camera.startPreview();
}
最佳答案
创建 PreviewFragment
,其中包含 ImageView
,您可以在其中显示从字节数组 data
创建的 Bitmap
。加载 fragment 。
在 PreviewFragment
中,加载 fragment 后,在 onViewCreated()
方法中执行以下操作:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
view.getHandler().postDelayed(new Runnable(){
@Override
public void run() {
getActivity().getSupportFragmentManager().beginTransaction().remove(PreviewFragment.this).commit();
}}, 5000);
}
确保遵循处理大位图的准则,以避免 OutOfMemoryException
。
关于java - 如何让应用程序在返回相机之前显示图片 5 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18346466/