欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

本文實例講述了Android實現(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ā)入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

最新評論