方法一:

/**
* 该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. EL表达式(1)

    JSP页面中支持使用EL表达式,EL全名为Expression Language.EL表达式的主要作用有: ① 获取数据: ② 执行运算: ③ 使用EL表达式的11大隐式对象: ④ 调用Java方法. ...

  2. UpdateWindow API函数的作用很明显

    待续 摘自<Delphi深度历险>

  3. spring mvc3中的addFlashAttribute方法

    spring mvc3中的addFlashAttribute方法  

  4. 测试kestrel的队列

    一.依赖环境的安装  1.sbt  wget http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.s ...

  5. cell中button怎么得到对应cell的indexpath 以及关于UITableViewCellContentView的问题

    ============================================================ 博文原创,转载请声明出处 电子咖啡-专注于移动互联网 ============ ...

  6. [Android学习笔记]try-catch

    private boolean test() { boolean result = true; String str = null; try { Log.d("test",&quo ...

  7. 安装logstash,elasticsearch,kibana三件套(转)

    logstash,elasticsearch,kibana三件套 elk是指logstash,elasticsearch,kibana三件套,这三件套可以组成日志分析和监控工具 注意: 关于安装文档, ...

  8. [C++STDlib基础]关于日期时间的操作——C++标准库头文件<ctime>

    总结 /* A.头文件<ctime> #if _GLOBAL_USING && !defined(RC_INVOKED) _STD_BEGIN 1.四个数据类型 using ...

  9. 通过设置Referer反"反盗链"

    package cn.searchphoto.util; import java.io.File; import java.io.FileOutputStream; import java.io.In ...

  10. VC6迁移到VS2008几个问题——良好的代码,从我做起,从现在开始。

    最近.有一个项目开发,需要使用一次项目的代码.只有当项目VC6下编译通过的,在VS2008下不一定编译通过,能编译通过也不一定能链接成功.以下总结一下我在一个VC6项目移植到VS2008中遇到的一些问 ...