2012-07-11 55 views

回答

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的是通过它,我们需要包括在屏幕上查看。你也可以通过这种方式从任何View中获取DrawingCache(没有getRootView())。

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

+0

可以请你帮我写手机插件?因为我对这项技术很陌生 – Thiru 2012-07-11 10:03:56

+1

当然,这里是一个教程,按照这个教程一步一步地进行,你将使用你自己的插件http://wiki.phonegap.com/w/page/36753494/How%20to%20Create %20a%20PhoneGap%20Plugin%20for%20Android http://www.adobe.com/devnet/html5/articles/extending-phonegap-with-native-plugins-for-android.html谢谢。 :) – SALMAN 2012-07-11 10:06:02

+0

我已经在android中完成了这项工作。但我非常困扰phonegap插件。我无法执行它。如果你知道,然后回答我。我在一个活动中拥有cnapshot代码。我如何添加这个,并在Phonegap中进行编码。请帮助我..我想尽快提交.. – Thiru 2012-07-11 11:50:35