簡體   English   中英

單擊菜單項保存活動圖像

[英]Save the Image of activity on click of menu item

我有一個活動,單擊菜單項后要保存,我想將屏幕圖像保存到我的設備中的特定文件夾中。 我該怎么做。

在后台顯示的圖像是ImageView,文本是textview。 我必須合並它們並將它們保存為單個圖像。

在此處輸入圖片說明

嘗試在菜單項單擊事件上使用以下代碼。

View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();

// give path of external directory to save image
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, "test.jpg");
FileOutputStream fos = null;

try {
    fos = new FileOutputStream(myPath);
    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.flush();
    fos.close();       
} catch (Exception e) {       
    e.printStackTrace();
}

其中視圖v是根布局...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM