Java 如何使应用程序在返回相机前显示图片5秒?
我正在制作一个摄像头应用程序,基本上我希望用户拍摄的图像在返回摄像头模式前显示5秒钟 此代码使其显示预览。但我会在它之后写些什么让它停留五秒钟呢? 谢谢Java 如何使应用程序在返回相机前显示图片5秒?,java,android,image,camera,Java,Android,Image,Camera,我正在制作一个摄像头应用程序,基本上我希望用户拍摄的图像在返回摄像头模式前显示5秒钟 此代码使其显示预览。但我会在它之后写些什么让它停留五秒钟呢? 谢谢 @Override public void onPictureTaken(byte[] data, Camera camera) { camera.startPreview(); } 您可以在线程中定义它。运行线程5秒钟,然后按如下方式停止: private Thread mSplashThread; private final
@Override
public void onPictureTaken(byte[] data, Camera camera) {
camera.startPreview();
}
您可以在线程中定义它。运行线程5秒钟,然后按如下方式停止:
private Thread mSplashThread;
private final static int SPLASH_SCREEN_TIME = 5000;
mSplashThread = new Thread(){
@Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
//Do your work
wait(SPLASH_SCREEN_TIME);
}
}
catch(InterruptedException ex){
}
// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen, xxx.class);
intent.putExtra("showTheme", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
};
创建
PreviewFragment
,其中包含ImageView
,您可以在其上显示从字节数组数据创建的位图。加载片段
在PreviewFragment
中,加载片段后,在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