簡體   English   中英

如何將活動轉換為圖像

[英]How to convert an activity into an image

我有一些帶有一些視圖的活動,在做了一些我希望將這個活動的外觀轉換為圖像並通過電子郵件發送之后。 我可以郵寄圖像,但是如何將該活動轉換為圖像? 可能嗎?

您可以以編程方式截取設備的屏幕截圖,這應該可以解決問題。 看看這個SO答案 ,它應該讓你開始。

通過捕獲drawing cache ,可以將應用程序的不同視圖渲染Bitmap對象。

請參閱http://blog.neurolive.net/2010/11/385/了解更多詳情。 (thx,對於偉大的教程)

特別

private Bitmap getScreenViewBitmap(View v) {
    v.setDrawingCacheEnabled(true);

    // this is the important code :)  
    // Without it the view will have a dimension of 0,0 and the bitmap will be null          
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache
}

似乎你會感興趣的。(只需找到你的頂級視圖並使用此方法來捕獲位圖)

暫無
暫無

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

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