0

我正在制作一个相机应用程序,基本上我希望用户拍摄的图像在返回相机模式之前显示 5 秒钟。

此代码使其显示预览。但是我会在它之后写什么让它停留五秒钟呢?谢谢!!

  @Override
public void onPictureTaken(byte[] data, Camera camera) {

  camera.startPreview();

}
4

2 回答 2

1

Create PreviewFragmentwhich has ImageViewyou'd display the Bitmapcreated from the byte array data。加载片段。

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.

于 2013-08-20T23:36:39.253 回答
0

You can define it in a thread. run the thread for 5 seconds snd then stop like this:

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();
            }
        };
于 2013-08-20T23:30:29.930 回答