首页 > 代码库 > AndEngine之ScreenCapture

AndEngine之ScreenCapture

AndEngine引擎提供了一个截图的类ScreenCapture

这个类的用法:ScreenCapture  cap= new ScreenCapture();无参构造函数

然后添加到场景中,如果不添加到场景中就截不到任何数据

她有两个主要方法

capture(final int pCaptureWidth, final int pCaptureHeight, final String pFilePath, final IScreenCaptureCallback pScreenCaptureCallback)

和 capture(final int pCaptureX, final int pCaptureY, final int pCaptureWidth, final int pCaptureHeight, final String pFilePath, final IScreenCaptureCallback pScreencaptureCallback)

pScreenCaptureCallback回调接口是当截图成功或失败后调用的 

用的是out = new FileOutputStream(pFilePath);
         pBitmap.compress(CompressFormat.PNG, 100, out);

 

还有就是AndEngine的***Activity有个方法runrunOnUiThread(runnable)能够在非UI线程中做一些UI操作,例如非UI线程不可以使用Toast,

但是runrunOnUiThread方法里面就可以使用

例如:

CaptureSampleActivity.this.runOnUiThread(new Runnable() {
                               
                                @Override
                                public void run() {
                                    Toast.makeText(getApplication(), "截图成功", Toast.LENGTH_LONG).show();
                                }
                            });

AndEngine之ScreenCapture