drawable-图片绘制
首先看一下,下端代码
private Bitmap createSelectedChip(RecipientEntry contact, TextPaint paint) {
int height = (int) mChipHeight;
int deleteWidth = height;
float[] widths = new float[1];
paint.getTextWidths(" ", widths);
CharSequence ellipsizedText = ellipsizeText(createChipDisplayText(contact), paint,
calculateAvailableWidth() - deleteWidth - widths[0]);
printDebugLog(TAG,"[createSelectedChip] " + ellipsizedText);
int width = Math.max( 0 /*deleteWidth * 2*/, (int) Math.floor(paint.measureText(ellipsizedText, 0,
ellipsizedText.length()))
+ (mChipPadding * 2) + deleteWidth);
/// @}
// Create the background of the chip.
//创建一个画布,宽为width,高为height
Bitmap tmpBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
//创建一个工具,这个工具的操作,都是在这个画布上进行的
Canvas canvas = new Canvas(tmpBitmap);
if (mChipBackgroundPressed != null) {
//创建一个矩形
Rect backgroundPadding = new Rect();
mChipBackgroundPressed.getPadding(backgroundPadding);
//获得一个图片的大小,这个应该是按比例压缩的感觉
mChipBackgroundPressed.setBounds(0, 0, width - deleteWidth, height);
//把这个压缩以后的图片绘制到这个画布上(图过工具)
mChipBackgroundPressed.draw(canvas);
//创建一个画笔,给他设定颜色
paint.setColor(sSelectedTextColor);
//通过工具跟画笔,绘制一个文字
canvas.drawText(ellipsizedText, 0, ellipsizedText.length(), mChipPadding,
getTextYOffset((String) ellipsizedText, paint, height), paint);
mChipDelete.setBounds(width - deleteWidth - backgroundPadding.left,
+ backgroundPadding.top/2,
width - backgroundPadding.right/2,
height);
mChipDelete.draw(canvas);
} else {
Log.w(TAG, "Unable to draw a background for the chips as it was never set");
}
return tmpBitmap;
}
如
Drawable drawable = xxxx;
drawable.setBounds(int, int, int, int);
drawable.draw(canvas);
setBounds 有人给出的解释是,绘制图片时候,相对于父容器的边距
但是,通过验证,我感觉应该是如下的解释,看图

drawable-图片绘制的更多相关文章
- ImageDrawer.js图片绘制插件
ImageDrawer.js图片绘制插件有以下一些可用的配置参数. Duration:整个动画或每个步骤的绘制时间(以秒为单位) Background:在绘图时将颜色放在图片上 Callback:绘画 ...
- canvas 2.0 图片绘制
绘制图片drawImage 2013.02.21 by 十年灯·一条评论 本文属于<html5 Canvas画图系列教程> 这里的绘制图片是指把一张现成的图片,绘制到Canvas上面. 有 ...
- 把一个base64编码的图片绘制到canvas (canvas的图片在转成dataurl)
把一个base64编码的图片绘制到canvas 需要引入jquery. <canvas id="myCanvas" width="800" height= ...
- 设置drawable图片
google官方建议在textView和imageView挨着的时候,建议使用drawable来显示图片 第一个方法:setCompoundDrawablesWithIntrinsicBounds(D ...
- GDI+ 如何将图片绘制成圆形的图片
大概意思就是不生成新的图片,而是将图片转换为圆形图片. 实现代码如下: private Image CutEllipse(Image img, Rectangle rec, Size size) { ...
- opengl打开本地bmp图片绘制
注意bmp图片的格式问题,32位ARGB 或者24位RGB.你所采用的素材一定要注意是多少位的就用多少位的.否则会显示错误的图片或者其他什么的错误. 代码如下 32位版本 #include < ...
- iOS-UIImage图片绘制颜色
- (UIImage *)dtk_setImageColor:(UIColor *)imageColor{ //获取画布 UIGraphicsBeginImageContextWithOptions( ...
- 微信小程序canvas把正方形图片绘制成圆形
wxml代码: <view class="result-page"> <canvas canvas-id='firstCanvas' style='width:1 ...
- canvas的图片绘制案例
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- GDI+ 怎样将图片绘制成圆形的图片
大概意思就是不生成新的图片,而是将图片转换为圆形图片. 实现代码例如以下: private Image CutEllipse(Image img, Rectangle rec, Size size) ...
随机推荐
- intellij idea 13
mac版 http://pan.baidu.com/s/1c0zjWU8 intellij idea 编辑器之于程序员,犹如鞋之于女人.有的女人赤脚都漂亮,性感. 有的女人赤身都没人看.程序员亦如此. ...
- c# 导出excel格式xlsx
string sb="";//sql字符串 AttachmentConfigSection configSection = ConfigurationManager.GetSect ...
- 【Django】Session
目录 介绍 Django中操作Session @ 介绍 Cookie虽然在一定程度上解决了"保持状态"的需求,但是由于Cookie本身最大支持4096字节,以及Cookie本身保存 ...
- Innodb锁的类型
Innodb锁的类型 行锁(record lock) 行锁总是对索引上锁,如果某个表没有定义索引,mysql就会使用默认创建的聚集索引,行锁有S锁和X锁两种类型. 共享锁和排它锁 Innodb锁有两种 ...
- Springboot 获取yml、properties参数
获取properties或yml文件的配置数据(两种方法)(默认的application文件或者自定义的yml和properties) 1.使用@Value()注解 1.1 配置数据 如:在prope ...
- Java并发包之Semaphore用法
多线程中的同步概念就是排着队去执行一个任务,执行任务的是一个一个的执行,并不能并行执行,这样的优点是有助于程序逻辑的正确性,不会出现线程安全问题,保证软件的系统功能上的运行稳定性, Semaphore ...
- jvm vmthread
http://www.360doc.com/content/15/0615/16/15758456_478311946.shtml http://www.51testing.com/html/95/1 ...
- SQL 自增列清零方法
SQL Identity自增列清零方法1.使用DBCC控制台命令: dbcc checkident(表名,RESEED,0) 2.truncate table 也可将当前标识值清零 但当有外键等约束时 ...
- 零基础学python-7.6 字符串格式化表达式
字符串格式化同意在一个单个的步骤中对一个字符串运行多个特定类型的替换 特别是给用户提示的时候,格式化很方便 实现方法: 1.格式化表达式,类似于c语音的printf 在表达式中,我们使用%二进制操作符 ...
- Codeforces 240E. Road Repairs 最小树形图+输出路径
最小树形图裸题,只是须要记录路径 E. Road Repairs time limit per test 2 seconds memory limit per test 256 megabytes i ...