android在如果绘制自定义的bitmap,然后返回给ImageView
来源:互联网 发布:apache ant zip maven 编辑:程序博客网 时间:2024/05/16 23:46
先来说一下FontMetrics这个类,这个类是关于字符属性和测量的类
用图可以更精确的知道各个属性的含义:
我们在Layout中有一个ImageView,我们可以通过:
<span style="white-space:pre"></span>ImageView item_image = (ImageView)findViewById(R.id.item_image);item_image.setImageBitmap(makeMessageCenterIcon());
这种方式来把bitmap来填入ImageView
下面做一个这种效果的,特别适合有消息通知的icon:
代码可以这样来写:
protected Bitmap makeMessageCenterIcon(){int mMsgCnt = 4;Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.desktop_messageicon);if(icon == null){return icon;}//make notice iconif(mMsgCnt > 0) {Bitmap noticeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.notice_count_bg);if(noticeIcon != null){int h = noticeIcon.getHeight();int w = noticeIcon.getWidth();Bitmap noticeIconBmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);//noticeIconBmp是最终需要的画字的bitmapCanvas noticeCanvas = new Canvas(noticeIconBmp);Paint noticeCntpaint = new Paint();noticeCntpaint.setAntiAlias(true);noticeCanvas.drawBitmap(noticeIcon, 0, 0, noticeCntpaint);noticeCntpaint.setTextAlign(Align.CENTER);noticeCntpaint.setColor(getResources().getColor(R.drawable.white));FontMetrics fontMetrics = noticeCntpaint.getFontMetrics(); float x = noticeIcon.getWidth() / 2;float y = (noticeIcon.getHeight() - fontMetrics.ascent) / 2 - 2; //fontMetrics是在baseline以上的字符最高处的位置noticeCanvas.drawText(String.valueOf(mMsgCnt), x, y, noticeCntpaint); //在canvas上的(x,y)的位置上写mMsgCnt//draw notice icon onto message iconh = icon.getHeight();w = icon.getWidth();Bitmap iconBmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);Canvas canvas = new Canvas(iconBmp);Paint paint = new Paint();paint.setAntiAlias(true);canvas.drawBitmap(icon, 0, 0, paint);float left = icon.getWidth() - noticeIcon.getWidth();float top = 0;canvas.drawBitmap(noticeIconBmp, left, top, paint);return iconBmp;}}return icon;}
0 0
- android在如果绘制自定义的bitmap,然后返回给ImageView
- android如果给imageview做圆角,如果在原有的bitmap上加上一些修饰的drawable
- Android自定义view之- BitMap的绘制
- Android ImageView圆角,绘制ImageView边框;Bitmap圆角
- Android 销毁ImageView的bitmap
- 自定义View之Bitmap/在Bitmap上绘制新的图形/Xfermode属性
- android 绘制圆形的ImageView
- Android开发:在ImageView上绘制圆环
- Android开发:在ImageView下绘制圆环
- 【android 优化】ImageView的Bitmap的使用
- Android 改变ImageView图片的Bitmap大小
- ImageView、Bitmap的属性android:scaleType
- android Imageview bitmap 占用内存空间的计算
- OpenGL在Android上绘制Bitmap
- 通过图片的url获取Bitmap对象,给Imageview使用
- Android: ImageView and Bitmap
- 用Bitmap自定义设置ImageView
- 在Bitmap上绘制Bitmap
- 个就每年投入没看到他一人就看他家的大门,等同于
- 退出MFC应用程序的方法集
- HDU 1106 排序 字符串模拟
- Storm on YARN
- POJ 3311 Hie with the Pie (状压DP)
- android在如果绘制自定义的bitmap,然后返回给ImageView
- Android SharaedPreferences 记住用户名密码
- 字符串-07. 说反话-加强版 (20)
- Windows服务创建及安装
- Java native
- JAVA 环境设置
- 无情的雨无情的你
- Android SharaedPreferences 记住用户名密码
- c#中new和override的用法区别