[Perl]通过GD模块获取字符/汉字的点阵

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

示例脚本应保存为utf8格式
Code: [全选] [展开/收缩] [Download] (Untitled.pl)

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";
    }
}

0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0011111111111111111111111000000000000000
0011111111111111111111111000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011000000001100000000011000000000000000
0011111111111111111111111000000000000000
0011111111111111111111111000000000000000
0011000000001100000000011000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000
0000000000001100000000000000000000000000

再来个
.

                                                                    ****                            
                                                                     *****                          
                                                                     *******                        
                                                                      ************                  
                                                                       ****************             
        *                                                            ***********      ***           
        ***                  *                                    ************       *****          
         ***                ***                           *     **************       *****          
         *****              ****                          *    ***************     *******          
          ****             *******                        ** *          *****     ********          
          ****            ********                        ***             ***   *********           
          *****          **********                       **                  *********             
          ****         ***********                        **                ********                
         ***         *************                       ***              *******                   
                    ******** ****                        ***           ********                     
                   ********  ****                       ****         ***********                    
                  ********   ****                       ****       *******  ****                    
                 ****  **    ***                       ****       ******    ****                    
                **           ***                       ****       ****     *****                    
               **           ****                       ****      ***       ****                     
    **        **            ***                        ***       *        ****                      
    **       **             ***                         **             *******                      
    ***      *             ****                         **             ******                       
   ****     **   ***       ***                                         *****                        
   ****    **************  ***                                         ******                       
   ****    *       ***********                                         *******                      
   ***     *         *********                                         **********                   
   ***    **           *********                                       ************                 
    **    *             **********                                    **************                
    **    *            **************                               *****************               
    **   **           *****  **********                           *********  ********               
    **   **          *****    **********                        *********    *******                
    **   **        ******       *********                      ********     ****                    
    **  ***   **********          ********                    *******         **                    
    **  ***    *******             *******                    *****           **                    
     *  ***      **                 ******                    ****            **                    
     * ***                            ****                    ***             **                    
     *****                             ****                    *             ***                    
      ****                                                     *             ***
posted @ 2017-05-15 10:00  vicyang  阅读(506)  评论(0编辑  收藏  举报