android中创建有自身特色的字符串
来源:互联网 发布:网络招商 编辑:程序博客网 时间:2024/05/01 15:09
android提供的字符串的字体格式很受限制。这里分享一种创建有自身特色字符串的方法,以供大家参考。代码如下:
public static Bitmap getNumberBitmap(Resources res, String inputStr, float hRatio) {
final int imageWidth = 8;final int imageHeight = 9;
char[] inputChar = inputStr.toCharArray();
Bitmap newBitmap = Bitmap.createBitmap(imageWidth * inputChar.length, imageHeight, Config.ARGB_8888);
Canvas cv = new Canvas(newBitmap);
Bitmap sourceBitmap = BitmapFactory.decodeResource(res, R.drawable.img_number);
Bitmap bitmap = null;
for (int i = 0; i < inputChar.length; i++) {
char c = inputChar[i];
switch (c) {
case '.':
bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, imageWidth, imageHeight);
break;
case '/':
bitmap = Bitmap.createBitmap(sourceBitmap, 8, 0, imageWidth, imageHeight);
break;
case '0':
bitmap = Bitmap.createBitmap(sourceBitmap, 16, 0, imageWidth, imageHeight);
break;
case '1':
bitmap = Bitmap.createBitmap(sourceBitmap, 24, 0, imageWidth, imageHeight);
break;
case '2':
bitmap = Bitmap.createBitmap(sourceBitmap, 32, 0, imageWidth, imageHeight);
break;
case '3':
bitmap = Bitmap.createBitmap(sourceBitmap, 40, 0, imageWidth, imageHeight);
break;
case '4':
bitmap = Bitmap.createBitmap(sourceBitmap, 48, 0, imageWidth, imageHeight);
break;
case '5':
bitmap = Bitmap.createBitmap(sourceBitmap, 56, 0, imageWidth, imageHeight);
break;
case '6':
bitmap = Bitmap.createBitmap(sourceBitmap, 64, 0, imageWidth, imageHeight);
break;
case '7':
bitmap = Bitmap.createBitmap(sourceBitmap, 72, 0, imageWidth, imageHeight);
break;
case '8':
bitmap = Bitmap.createBitmap(sourceBitmap, 80, 0, imageWidth, imageHeight);
break;
case '9':
bitmap = Bitmap.createBitmap(sourceBitmap, 88, 0, imageWidth, imageHeight);
break;
}
cv.drawBitmap(bitmap, imageWidth * i, 0, null);
bitmap.recycle();
}
//save all clip
cv.save( Canvas.ALL_SAVE_FLAG );
//store
cv.restore();
Bitmap expandBitmap = Bitmap.createScaledBitmap(newBitmap, Math.round(newBitmap.getWidth() * hRatio), Math.round(newBitmap.getHeight() * hRatio),true);
newBitmap.recycle();
return expandBitmap;
}
所使用的资源文件如下:
R.drawable.img_number
- android中创建有自身特色的字符串
- 几个有特色的软件
- unity3d的特色有哪些
- 比较有特色的slogan
- android 中list的创建有困难
- Android中获取手机自身的信息
- 昆仑叶哲华:如何才能建立起具备自身特色的品牌
- 部分有特色的Oracle函数
- 打造有企业特色的ERP
- 有关于在Java 类的静态初始化块中创建一个自身实例的问题。
- 具有Android特色的文件的保存
- 银行市场风险管理系统实施中,几个知名的厂商的系统各有什么特色?
- 如何在vs2013中创建特色类模板
- ext2 有几个特色
- Android 4.2: 果冻豆的新特色
- Android 特色开发,基于位置的服务
- Android 特色开发,基于位置的服务
- [ZT]一些著名或有特色的论坛系统
- 使用HashMap输出的顺序
- Camera总结
- 在windows上搭建一个SSH隧道Set up a Windows SSH tunnel in 10 minutes or less)
- Java的Socket(一)
- H.264-AVC视频编码原理及实现(一)
- android中创建有自身特色的字符串
- Qt 程序启动画面QSplashScreen的使用
- OSGi代码权限与Java Security机制
- HashMap java.util.ConcurrentModificationException
- 火狐和IE的window.event对象详解
- template , for_each , fill
- 进入mac时代,xcode来了
- http://blog.csdn.net/wei_wei_hnu/article/details/6634112
- android学习笔记之二