2012-07-11 54 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