GIF图像转Ascall文字图像

GIF图像Ascall

GIF图像是简单的调色板图像,和BMP图像的编码基本相同。对GIF图像进行解码可以得到由图像的颜色索引值组成的矩阵。对象素点进行8×16的组块,可以将图像用Ascall码替换。

l 替换原理:

1. Ascall码的灰度

打开Notepad,然后输入1, 2 并将其选取。然后进行屏幕拷贝(Alt+PrtSc),并打开PaintView中将其放大600%并显示网格,如下图所示:

<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 362.25pt; HEIGHT: 340.5pt" type="#_x0000_t75"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C02%5Cclip_image001.png" o:title=""></imagedata></shape>

我们可以数数1占用多少个点,22点;2占用28点。那么在蓝色区域有8×16个点。所以可以知道1的灰度是<shape id="_x0000_i1026" style="WIDTH: 81.75pt; HEIGHT: 30.75pt" type="#_x0000_t75" o:ole=""><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C02%5Cclip_image003.wmz" o:title=""></imagedata></shape>.以下是所有Ascall的灰度值:

private char[] character={ ' ', '-', '\'', '.', '`' ,',','^','=',

':','"','~','+','_',';','<','>',

'/','\\','r','*','(',')','1','7',

'T','I','{','}','L','z','!','c',

's','?','i','t','f','J','l','F',

'a','x','e','Z','S','|','v','5',

'2','Y','o','u','n','E','P','X',

'C','4','3','w','j','k','[',']',

'9','6','h','d','V','G','b','$',

'&','m','D','U','A','O','K','R',

'8','H','p','q','B','W','0','Q',

'%','y','M','#','N','g',' '};

private int[] gray= {0,6,6,6,7,10,10,12,12,12,14,14,

16,16,18,18,20,20,20,21,22,22,

22,22,22,22,22,22,22,22,22,22,

22,22,24,24,24,24,24,25,26,26,

26,26,26,26,26,27,28,28,28,29,

29,29,30,30,30,31,31,32,32,32,

32,32,32,32,33,34,34,34,34,34,

35,35,36,36,36,36,36,38,38,38,

38,38,39,39,40,40,40,40,41,42,

42, 44, 47};

2. GIF图像的灰度

GIF图像的灰度很容易表示:<shape id="_x0000_i1027" style="WIDTH: 195.75pt; HEIGHT: 15.75pt" type="#_x0000_t75" o:ole=""><font face="Times New Roman"> <imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C02%5Cclip_image005.wmz" o:title=""></imagedata></font></shape>

3. 替换方式

GIF图像分成8×16的小块,并计算各小块的平均灰度值。接着和Ascall灰度比较选择最恰当的Ascall替换一个8×16的小块。

l 转换软件:

<shape id="_x0000_s1026" style="MARGIN-TOP: 23.55pt; Z-INDEX: -2; LEFT: 0px; MARGIN-LEFT: 2in; WIDTH: 133.35pt; POSITION: absolute; HEIGHT: 169.35pt; TEXT-ALIGN: left" type="#_x0000_t75" wrapcoords="-121 0 -121 21504 21600 21504 21600 0 -121 0"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C02%5Cclip_image007.jpg" o:title="lena"></imagedata><wrap type="tight"></wrap></shape>实验的图像为Lena的修改图,如下:


软件的执行效果如下:

<shape id="_x0000_s1027" style="MARGIN-TOP: 0px; Z-INDEX: -1; LEFT: 0px; MARGIN-LEFT: 18pt; WIDTH: 385.35pt; POSITION: absolute; HEIGHT: 394pt; TEXT-ALIGN: left" type="#_x0000_t75" wrapcoords="-42 0 -42 21559 21600 21559 21600 0 -42 0"><font size="3"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C02%5Cclip_image009.png" o:title=""></imagedata><wrap type="tight"></wrap></font></shape>

转换后的Ascall图像效果如下:

<shape id="_x0000_i1028" style="WIDTH: 181.5pt; HEIGHT: 234pt" type="#_x0000_t75"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C02%5Cclip_image011.png" o:title=""></imagedata></shape>

顺便贴上Ascall码对应的灰度值:

private char[] character={ ' ', '-', '\'', '.', '`' ,',','^','=', ':','"','~','+','_',';','<','>', '/','\\','r','*','(',')','1','7', 'T','I','{','}','L','z','!','c', 's','?','i','t','f','J','l','F', 'a','x','e','Z','S','|','v','5', '2','Y','o','u','n','E','P','X', 'C','4','3','w','j','k','[',']', '9','6','h','d','V','G','b','$', '&','m','D','U','A','O','K','R', '8','H','p','q','B','W','0','Q', '%','y','M','#','N','g',' '};


private int[] gray= {0,6,6,6,7,10,10,12,12,12,14,14, 16,16,18,18,20,20,20,21,22,22, 22,22,22,22,22,22,22,22,22,22, 22,22,24,24,24,24,24,25,26,26, 26,26,26,26,26,27,28,28,28,29, 29,29,30,30,30,31,31,32,32,32, 32,32,32,32,33,34,34,34,34,34, 35,35,36,36,36,36,36,38,38,38, 38,38,39,39,40,40,40,40,41,42, 42, 44, 47};

你可能感兴趣的:(C++,c,F#,C#,ext)