最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)將View保存成Bitmap的方法

 更新時間:2016年06月14日 09:46:48   作者:ztp800201  
這篇文章主要介紹了Android實(shí)現(xiàn)將View保存成Bitmap的方法,涉及Android畫布Canvas、位圖bitmap及View的相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了Android實(shí)現(xiàn)將View保存成Bitmap的方法。分享給大家供大家參考,具體如下:

1、

public Bitmap convertViewToBitmap(View view){
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
        Bitmap.Config.ARGB_8888);
    //利用bitmap生成畫布
    Canvas canvas = new Canvas(bitmap);
    //把view中的內(nèi)容繪制在畫布上
    view.draw(canvas);
  return bitmap;
}

2、

/**
* save view as a bitmap
*/
private Bitmap saveViewBitmap(View view) {
// get current view bitmap
  view.setDrawingCacheEnabled(true);
  view.buildDrawingCache(true);
  Bitmap bitmap = view.getDrawingCache(true);
  Bitmap bmp = duplicateBitmap(bitmap);
  if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); bitmap = null; }
  // clear the cache
  view.setDrawingCacheEnabled(false);
  return bmp;
}
public static Bitmap duplicateBitmap(Bitmap bmpSrc)
{
  if (null == bmpSrc)
    { return null; }
  int bmpSrcWidth = bmpSrc.getWidth();
  int bmpSrcHeight = bmpSrc.getHeight();
  Bitmap bmpDest = Bitmap.createBitmap(bmpSrcWidth, bmpSrcHeight, Config.ARGB_8888); if (null != bmpDest) { Canvas canvas = new Canvas(bmpDest); final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight);
  canvas.drawBitmap(bmpSrc, rect, rect, null); }
  return bmpDest;
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論

昭苏县| 会理县| 石棉县| 开封市| 洪泽县| 介休市| 宁城县| 漳州市| 梅河口市| 留坝县| 宜兰市| 翁牛特旗| 浮山县| 香河县| 肃宁县| 喀喇| 孝义市| 南木林县| 宝兴县| 安阳市| 威宁| 醴陵市| 泗水县| 宜君县| 永顺县| 嘉定区| 乐安县| 横山县| 东方市| 利辛县| 博白县| 伊宁县| 新郑市| 中山市| 奇台县| 天台县| 弋阳县| 青阳县| 鲁山县| 湘潭县| 开江县|