原来Perl获取汉字的点阵如此简单

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
PerlMonk
渐入佳境
渐入佳境
帖子: 49
注册时间: 2016年09月19日 10:20
联系:

原来Perl获取汉字的点阵如此简单

帖子 PerlMonk »

示例脚本应保存为utf8格式
use GD;
use utf8;
my $gd = GD::Image->new(40, 20); #1
my $black = $gd->colorAllocate( 0, 0, 0);
my $white = $gd->colorAllocate(255, 255, 255);
$gd->stringTTF($white, "C:\\windows\\fonts\\msyh.ttf", 20, 0, 0, 20, "中");

my $dt = $gd->wbmp( $black );
my @dts = map { ord($_) } split('', $dt);

for my $e (4 .. $#dts)
{
printf "%08b", $dts[$e];
if (($e-4+1) % 5 == 0 )
{
print "\n";
}
}
[ascii]0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0011111111111111111111111000000000000000
0011111111111111111111111000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011111111111111111111111000000000000000
0011111111111111111111111000000000000000
0011000000001100000000011000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000[/ascii]
头像
PerlMonk
渐入佳境
渐入佳境
帖子: 49
注册时间: 2016年09月19日 10:20
联系:

Re: 原来Perl获取汉字的点阵如此简单

帖子 PerlMonk »

再来个
[ascii].

****
*****
*******
************
****************
* *********** ***
*** * ************ *****
*** *** * ************** *****
***** **** * *************** *******
**** ******* ** * ***** ********
**** ******** *** *** *********
***** ********** ** *********
**** *********** ** ********
*** ************* *** *******
******** **** *** ********
******** **** **** ***********
******** **** **** ******* ****
**** ** *** **** ****** ****
** *** **** **** *****
** **** **** *** ****
** ** *** *** * ****
** ** *** ** *******
*** * **** ** ******
**** ** *** *** *****
**** ************** *** ******
**** * *********** *******
*** * ********* **********
*** ** ********* ************
** * ********** **************
** * ************** *****************
** ** ***** ********** ********* ********
** ** ***** ********** ********* *******
** ** ****** ********* ******** ****
** *** ********** ******** ******* **
** *** ******* ******* ***** **
* *** ** ****** **** **
* *** **** *** **
***** **** * ***
**** * ***[/ascii][/size]
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 0 访客