0

我希望代码片段拍摄当前屏幕的快照并将其存储在 SD 卡中,方法是使用 phonegap android 按下按钮。如果有人知道,请帮助我。提前致谢。

4

1 回答 1

2

使用以下代码:

    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   

// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

OutputStream fout = null;
imageFile = new File(mPath);

try {
    fout = new FileOutputStream(imageFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
    fout.flush();
    fout.close();

} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

这里的 MyView 是我们需要包含在屏幕中的视图。您也可以通过这种方式从任何视图中获取 DrawingCache(无需 getRootView())。

这是 Android 的代码,但对于 phoneGap,您必须为此代码片段制作插件。谢谢

于 2012-07-11T10:01:02.280 回答