方法一:

/**
* 该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. JavaScript快速入门(五)——表达式运算

    赋值运算 赋值运算的形式为左值 = 右值.如果同个表达式中有多个赋值运算,则从右到左运算.例如: a = b = c; // 和下面两行等价 b = c; a = b; 另外一种赋值运算的形式叫做复合 ...

  2. CMDeviceMotion使用

    CMDeviceMotion使用 by 吴雪莹 manager = [[CMMotionManager alloc] init]; ViewController *__weak weakSelf=se ...

  3. String,StringBuffer与StringBuilder差异??

    String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全) 简要地, String 类型和 StringBuffer 类型的主要性能差 ...

  4. App 运营 推广相关

    基本要素 1.定位和产品 2.取个好名字,一目了然+下载冲动 3.设计一个好图标,有感性和直观的认识 4.做好产品的说明.关键字,截图(前1-2行是重点) 5.做市场的排名(相关因素如下)   (1) ...

  5. 在toolbar里动态创建多个button(ext.net)

    private void setOneMenu() { string sql = "select id,name,gids from Config where name<>'高级 ...

  6. 跟我一起学extjs5(11--自己定义模块的设计)

    跟我一起学extjs5(11--自己定义模块的设计)        从这一节開始我们来设计并完毕一个自己定义模块.我们先来确定一个独立的模块的所能定义的一些模块信息. 下面信息仅仅是我自己在开发过程中 ...

  7. sublime_text 破解

    之前一直使用vi的,但是总觉的vi差了一点什么,不够现代化,老古董了.没办法,只是因为vi在linux下面是预装的,有些时候必须使用vi. 不过除了这种情况之外,vi的可配置性比较高,但是在使用了一段 ...

  8. 与众不同 windows phone (26) - Contacts and Calendar(联系人和日历)

    原文:与众不同 windows phone (26) - Contacts and Calendar(联系人和日历) [索引页][源码下载] 与众不同 windows phone (26) - Con ...

  9. c/c++ extern “C”

    c/c++ extern “C” 常见的样式 extern “C”{ ... } extern "C" return-type func-name(type , type ){} ...

  10. iPhone开发【一】从HelloWorld開始

    转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/8013553 作者:张燕广 从经典的HelloWorld開始踏入iPhon ...