方法一:

/**
* 该View绘制到Bitmap上
* @param view 须要绘制的View
* @param width 该View的宽度
* @param height 该View的高度
* @return 返回Bitmap对象
* add by csj 13-11-6
*/
public Bitmap getViewBitmap(View comBitmap, int width, int height) {
Bitmap bitmap = null;
if (comBitmap != null) {
comBitmap.clearFocus();
comBitmap.setPressed(false); boolean willNotCache = comBitmap.willNotCacheDrawing();
comBitmap.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent
// for the duration of this operation
int color = comBitmap.getDrawingCacheBackgroundColor();
comBitmap.setDrawingCacheBackgroundColor(0);
float alpha = comBitmap.getAlpha();
comBitmap.setAlpha(1.0f); if (color != 0) {
comBitmap.destroyDrawingCache();
} int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
comBitmap.measure(widthSpec, heightSpec);
comBitmap.layout(0, 0, width, height); comBitmap.buildDrawingCache();
Bitmap cacheBitmap = comBitmap.getDrawingCache();
if (cacheBitmap == null) {
Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")",
new RuntimeException());
return null;
}
bitmap = Bitmap.createBitmap(cacheBitmap);
// Restore the view
comBitmap.setAlpha(alpha);
comBitmap.destroyDrawingCache();
comBitmap.setWillNotCacheDrawing(willNotCache);
comBitmap.setDrawingCacheBackgroundColor(color);
}
return bitmap;
}

方法二:

private Bitmap getViewBitmap(View v) {
v.clearFocus();
v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent
// for the duration of this operation
int color = v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0); if (color != 0) {
v.destroyDrawingCache();
}
v.buildDrawingCache();
Bitmap cacheBitmap = v.getDrawingCache();
if (cacheBitmap == null) {
Log.e("Folder", "failed getViewBitmap(" + v + ")", new RuntimeException());
return null;
} Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color); return bitmap;
}

方法三:

View view = mLauncher.getDragLayer();
view.setDrawingCacheEnabled(true);
Bitmap bitmap = view.getDrawingCache();

版权声明:本文博客原创文章,博客,未经同意,不得转载。

该View转换成Bitmap方法的更多相关文章

  1. Android 将drawable下的图片转换成bitmap、Drawable

    将drawable下的图片转换成bitmap . Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.xxx ...

  2. Android View转换成图片保存

    package zhangphil.viewtoimage; import java.io.File;import java.io.FileOutputStream; import android.o ...

  3. XML转换成数组方法

    <?php function xmlToArray2($xml) { // 将XML转为array $array_data = json_decode(json_encode(simplexml ...

  4. android将drawable下的图片转换成bitmap

    将drawable下的图片转换成bitmap 1. Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.xx ...

  5. 将一个读取流转换成bitmap对象

     将一个读取流转换成bitmap对象:         BitmapFactory:可以将文件,读取流,字节数组转换成一个Bitmap对象.         Bitmap bitmap = Bitma ...

  6. C#将Word转换成PDF方法总结(基于Office和WPS两种方案)

    有时候,我们需要在线上预览word文档,当然我们可以用NPOI抽出Word中的文字和表格,然后显示到网页上面,但是这样会丢失掉Word中原有的格式和图片.一个比较好的办法就是将word转换成pdf,然 ...

  7. Android网络图片转换成bitmap保存到本地指定文件夹

    下列代码,请求网络图片转换为bitmap,然后保存到指定文件夹,微信,QQ分享,要求缩略图不大于32kb 压缩图片代码,使用了Glide来进行图片压缩处理 Glide.get(ShopDetailsA ...

  8. Spring MVC 后端获取前端提交的json格式字符串并直接转换成control方法对应的参数对象

    场景: 在web应用开发中,spring mvc凭借出现的性能和良好的可扩展性,导致使用日渐增多,成为事实标准,在日常的开发过程中,有一个很常见的场景:即前端通过ajax提交方式,提交参数为一个jso ...

  9. 将Object转换成Dictionary方法

    如果Object是Dictionary类型,直接返回 如果Object是NameValueCollection类型,则添加到Dictionary里 如果Object是Hashtable类型,添加到Di ...

随机推荐

  1. 把HTML5网页封装成APP,APK的方法

     phonegap appcan HBuilder的native.js     推荐你用两个东西打包 一个是ionic,一个是hbuilder,Maven,apicloud   http://mobi ...

  2. ubuntu14操作系统chrome标签和书签乱码解决

    ubuntu操作系统更新后.发现chrome标签和书签中文都无法显示. 解决的方法: 打开配置文件 sudo vim /etc/fonts/conf.d/49-sansserif.conf <! ...

  3. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  4. UE4的编程C++创建一个FPSproject(两)角色网格、动画、HUD、子弹类

    立即归还,本文将总结所有这些整理UE4有关角色的网络格.动画.子弹类HUD一个简单的实现. (五)角色加入网格 Character类为我们默认创建了一个SkeletaMeshComponent组件,所 ...

  5. 【Unity3D】【NGUI】UILabel

    原文:http://www.tasharen.com/forum/index.php?topic=6706.0 NGUI讨论群:333417608 概述 UILabel是用来显示文本的脚本,继承自UI ...

  6. MSYS2 环境搭建(在Qt Creator可以设置环境变量来进行引用这些库)

    本机环境:Windows XP 32位MSYS2地址:http://sourceforge.net/projects/msys2/ 下载32位版本,地址:http://sourceforge.net/ ...

  7. Delphi Socket的最好项目——FastMsg IM(还有一些IM控件),RTC,RO,Sparkle等等,FileZilla Client/Server,wireshark,NSClient

    https://www.nsclient.org/nsclient/ 好好学习,天天向上

  8. [置顶] ※数据结构※→☆线性表结构(queue)☆============循环队列 顺序存储结构(queue circular sequence)(十)

    循环队列 为充分利用向量空间,克服"假溢出"现象的方法是:将向量空间想象为一个首尾相接的圆环,并称这种向量为循环向量.存储在其中的队列称为循环队列(Circular Queue). ...

  9. Java调用cmd命令 打开一个站点

    使用Java程序打开一个站点 近期做了个东西使用SWT技术在一个client程序 须要升级时在提示升级 点击窗口上的一个连接 打开下载网页 花费了我非常长时间 用到了把它记录下来  怕是忘记,须要时能 ...

  10. ExtJs4 笔记(5) Ext.Button 按钮

    id="li2"></li> <li id="li3"></li> </ul> </div> ...