1.点阵字库
点阵字库是把每一个汉字都分成16×16或24×24个点,然后用每个点的虚实来表示汉字的轮廓,常用来作为显示字库使用,这类点阵字库汉字最大的缺点是不能放大,一旦放大后就会发现文字边缘的锯齿。
矢量字库保存的是对每一个汉字的描述信息,比如一个笔划的起始、终止坐标,半径、弧度等等。在显示、打印这一类字库时,要经过一系列的数学运算才能输出结果,但是这一类字库保存的汉字理论上可以被无限地放大,笔划轮廓仍然能保持圆滑,打印时使用的字库均为此类字库.
2.点阵字库结构
在汉字的点阵字库中,每个字节的每个位都代表一个汉字的一个点,每个汉字都是由一个矩形的点阵组成,0代表没有,1代表有点,将0和1分别用不同颜色画出,就形成了一个汉字,常用的点阵矩阵有12*12, 14*14, 16*16三种字库。 字库根据字节所表示点的不同有分为横向矩阵和纵向矩阵,目前多数的字库都是横向矩阵的存储方式(用得最多的应该是早期UCDOS字库),纵向矩阵一般是因为有某些液晶是采用纵向扫描显示法,为了提高显示速度,于是便把字库矩阵做成纵向,省得在显示时还要做矩阵转换。我们接下去所描述的都是指横向矩阵字库。
对于16*16的矩阵来说,它所需要的位数共是16*16=256个位,每个字节为8位,因此,每个汉字都需要用256/8=32个字节来表示。 即每两个字节代表一行的16个点,共需要16行,显示汉字时,只需一次性读取32个字节,并将每两个字节为一行打印出来,即可形成一个汉字.
16*16:
public class Font16 { private Context context; public Font16(Context context) { this.context = context; } private final static String ENCODE = "GB2312"; private final static String ZK16 = "HZK16"; private boolean[][] arr; int all_16_32 = 16; int all_2_4 = 2; int all_32_128 = 32; public boolean[][] drawString(String str) { byte[] data = null; int[] code = null; int byteCount; int lCount; arr = new boolean[all_16_32][all_16_32]; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) < 0x80) { continue; } code = getByteCode(str.substring(i, i + 1)); data = read(code[0], code[1]); byteCount = 0; for (int line = 0; line < all_16_32; line++) { lCount = 0; for (int k = 0; k < all_2_4; k++) { for (int j = 0; j < 8; j++) { if (((data[byteCount] >> (7 - j)) & 0x1) == 1) { arr[line][lCount] = true; System.out.print("@"); } else { System.out.print(" "); arr[line][lCount] = false; } lCount++; } byteCount++; } System.out.println(); } } return arr; } protected byte[] read(int areaCode, int posCode) { byte[] data = null; try { int area = areaCode - 0xa0; int pos = posCode - 0xa0; InputStream in = context.getResources().getAssets().open(ZK16); long offset = all_32_128 * ((area - 1) * 94 + pos - 1); in.skip(offset); data = new byte[all_32_128]; in.read(data, 0, all_32_128); in.close(); } catch (Exception ex) { } return data; } protected int[] getByteCode(String str) { int[] byteCode = new int[2]; try { byte[] data = str.getBytes(ENCODE); byteCode[0] = data[0] < 0 ? 256 + data[0] : data[0]; byteCode[1] = data[1] < 0 ? 256 + data[1] : data[1]; } catch (Exception ex) { ex.printStackTrace(); } return byteCode; } }
自定义SurfaceView:
public class MySurfaceView extends SurfaceView { private Context mContext; private SurfaceHolder holder; public MySurfaceView(Context context) { super(context); // TODO Auto-generated constructor stub this.mContext = context; holder = this.getHolder(); } public MySurfaceView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub this.mContext = context; holder = this.getHolder(); } public MySurfaceView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // TODO Auto-generated constructor stub this.mContext = context; holder = this.getHolder(); } /** * show font * * @param font_kind * the font type, has 16,24,32 * @param font * draw font * @param startx * the font coordinate start x value * @param starty * the font coordinate start y value * @param beishu * the font magnification multiple * @param type * draw font use icon,1 is flower,2 is love */ public void show_font16(int font_kind, String font, int startx, int starty, int beishu, int type) { boolean[][] arr = null; int weith = 16; int height = 16; if (font_kind == 16) { weith = 16; height = 16; arr = new boolean[weith][height]; Font16 font16 = new Font16(mContext); arr = font16.drawString(font); } else if (font_kind == 24) { weith = 24; height = 24; arr = new boolean[weith][height]; Font24 font24 = new Font24(mContext); arr = font24.drawString(font); } else { weith = 32; height = 32; arr = new boolean[weith][height]; Font32 font32 = new Font32(mContext); arr = font32.drawString(font); } for (int i = 0; i < weith; i++) { for (int j = 0; j < height; j++) { try { Thread.sleep(25); } catch (InterruptedException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } float x = (float) j; float y = (float) i; if (arr[i][j]) { Bitmap bitmap = null; if (type == 1) { bitmap = BitmapFactory.decodeStream(mContext.getResources().openRawResource(R.drawable.hua)); } else if (type == 2) { bitmap = BitmapFactory.decodeStream(mContext.getResources().openRawResource(R.drawable.love)); } int bw = bitmap.getWidth(); int bh = bitmap.getHeight(); synchronized (holder) { Canvas c = null; try { c = holder.lockCanvas(new Rect(startx + (int) x * beishu, starty + (int) y * beishu, startx + (int) x * beishu + bw, starty + (int) y * beishu + bh)); Paint p = new Paint(); p.setColor(Color.RED); c.drawBitmap(bitmap, startx + x * beishu, starty + y * beishu, p); } catch (Exception e) { e.printStackTrace(); } finally { try { if (c != null) { holder.unlockCanvasAndPost(c);// 结束锁定画图,并提交改变。 } } catch (Exception e) { e.printStackTrace(); } } } } } } } }
相关推荐
29种Android字库ttf文件,包括楷体,隶书,微软雅黑等常用字库,里面是百度云盘的下载地址。
12*12点阵中文字库!做嵌入式需要的。
android Tesseract字库训练-英文 子库训练必备的Tesseract3.01和jTessBoxEditor安装程序、字库训练步骤、android扫描demo、字库训练成功之后的文件
包括:子库训练必备的Tesseract3.01和jTessBoxEditor安装程序、字库训练步骤、android扫描demo、字库训练成功之后的文件
显示系统时间,通过点阵的方式,对理解点阵字库很有帮助。
为android提供的二值化jni库,和完整demo,比Java代码的效率高10s! 一个基于jni的图像处理工具 包括二值化 灰度化 膨胀 腐蚀 等等 是android上图像处理的好例子 还能提高处理速度!实现点阵图的转化
Android Studio中文汉化jar。先关闭Android Studio,然后将resources_cn.jar放到安装目录lib文件夹下,重新打开Android Studio即可
android导入第三方字库,ttf或otf格式文件
Android 添加多国语言 只要有下面几个步骤,就可以实现新曾加一种语言的显示支持: 1. 需要有可以显示该语言的字体库.ttf,在网上下载; 2. 需要修改的地方主要有 1) 将下载的字体文件拷贝到:./frameworks/base/...
《Android框架揭秘》通过对Android系统源代码的分析,主要介绍Android框架的初始化过程及主要组件的工作原理。作者直接分析和整理了Android框架的主要源代码,并详细讲解了理解框架工作原理所需的各种基础知识和构成...
LED点阵书写显示屏-总结 很好的一本书 费心整理的 喜欢的评个好评哈 谢谢
常见的字体库,而Android字体库,这本来是一个很大的库的,我通过字体压缩工具已经把字体库的文件缩小了很多,可以直接下载使用,不需要再用工具转换
QML on Android 在小米5s手机上中文显示异常,重新设置软件调用的默认字库
第2篇为应用开发篇,通过实例介绍了Android UI布局、Android人机界面、手机硬件设备的使用、Android本地存储系统、Android中的数据库、多线程设计、Android传感器、Android游戏开发基础、Android与Internet,以及...