Four key technologies for character painting software

zhaozj2021-02-17  35

Four key technologies for character painting software

First key technology: Chinese custom library reading technology

Using Chinese graphic library technology can be independent of the operating system, let's first understand the basic principles of the point of the penalty library as follows, below is a "word" dot mapping, one Chinese character in the 16-point box is 16x16 points, Each line uses two bytes, as shown in the first line of hexadecimal: 0x02 and 0x00, so a Chinese word needs to occupy 2x16 bytes in the 16-point box, 24 o'clock, the 24-point box is required to be 3x24 Bytes, below, we only take 16 o'clock fonts as an example, other dot matrix.

██████ ████████████████ ██████████ ████ ██████████ ███ █ █████████ ██████ ██████████████ ██████████████ ███████ ███████ █████ ██ ████████ ██████████████ █████████████ ██ ███████████████ █████████████ █ █████████████ █████ ████

The following function returns the character drawing text of the specified string Function Get16 (Const AWORD, AFOREGROUND): String; Function GetBit (const c, n: byte): integer; begin result: = (c shr n) and 1 End; var lyn: integer; ifilesize: integer; s: string; k, l, i, p: integer; cw: array [0..31] of char; qu_ma, wei_ma: integer; file16: file; begin : = length (AWord); AssignFile (File16, piProgramInfo.Path 'HZK16'); FileMode: = fmOpenReadWrite; end; iFileSize:: finally FileMode; = fmOpenRead; try Reset (File16,1) = FileSize (File16); try for L: = 1 To Ilen Div 2 Do Begin K: = L * 2-1; // If not Chinese characters, enter a while k <= Ilen do begin if byType (AWORD, K) = mbleadbyte the Break; Inc (INC) K); end; if k> Ilen dam; IF ((AWORD [K]) and $ 80) <> 0) THEN BEGIN Q_MA: = ORD (AWORD [K]) - 161; wei_ma: = ORD (AWord [K 1]) - 1 61; if (94 * qu_ma wei_ma) * 32 32> iFilesize Then Continue; try seek (file16, (94 * qu_ma wei_ma) * 32); Except myMessageBox ('fseek call fail!'); Exit; Blockread (File16, CW, 32);

For i: = 0 to 15 do begin for p: = 7 DOWNTO 0 do begin if getbit (ORD (CW [i * 2]), p) = 1 THEN S: = S AFOREGROUND ELSE S: = S ABACKGROUND; End; for p: = 7 DOWNTO 0 DO Begin if getbit (ORD (CW [i * 2 1]), P) = 1 THEN S: = S: = S ABACKGROUND; END; s: = S # 13 # 10; end; end; end; finally closefile (file16); end; result: = s; end;

Second Key Technologies: Use the system font to convert actually using a system font. It is a very free way, because so we don't have to care about the technology of the word library, all of which is handed over to the system, let us make full use of system resources. If we define a device, set the various properties of the device, including the width, height, font, color, etc., then draw the text above, you want to convert to a character painting, just need to put the dot matrix on the device Convert to text. With the CreateFontIndirect function, use DrawText to draw a rich text effect. Implement a complete character painting

Here is the result of the conversion of the Song Song █████ ███████ ████████ ███ ████████ ████████ ██ ██████ ██████ ███████████ ███████████ ████████ █████ █████████████

The following is the result of the 9th @ black body ██████████████ ███ ██████ ████ ██████ ██ █████ █ █ █ █████ █ █ █ ██ ██ ███ █ ██ ██ ███ █ ██ ██████ ████ ██████ ███ ██ ██████████████

Third key technology: Image Conversion To text To convert images to text, this is a big difficult, that is, there is no color, so we specially introduced a concept: text grayscale, just put different letters on the screen The size of the display is sorted to get a grayscale meter, with this grayscale to convert the picture, can achieve a better effect. The following function can convert a bitmap into text, ABIT is a bitmap, agray is a grayscale Function ImageText (Abit: string): string; var x, y: integer; s: string; pcolor: longint ; R, G, B: byte; IGRAY: integer;

SGRAYLEN: Integer; IIndex: integer; begin s: = '; sgrayper: = agray; IGRAYLEN: = Length (sgrayper); for y: = 0 to abit.Height-1 Do Begin for x: = 0 To Abit.width-1 Do Begin Pcolor: = Abit.canvas.pixels [x, y]; r: = pcolor and $ ff; g: = (pcolor shr 8) and $ ff; b: = (Pcolor SHR 16) And $ ff;

IGRAY: = Hibyte (R * 77 G * 151 B * 28); IIndex: = (IGRAY * IGRAYLEN DIV 255); if IIndex <1 Then IIdex: = 1; if = fDex> IGRAYLEN THENDEX: = IGRAYLEN; S : = S SGRAYPER [IINDEX]; END; S: = S CRLF; End; Result: = S; END; this is a common and better grayscale: "MnHQ $ OC? 7>!": ';. "

Fourth Key Technique: Convert text to images to convert text to images, you must get two important parameters: the width and high after conversion, to get these two parameters, we can use the getTextExtentPoint32 function, the function is defined as follows : Function gettextextentPoint32 (DC: hdc; str: pchar; count: integer; var size: tsize): BOOL; DC Incoming device handle Str is text content count is the text length (byte) size Return width and high in actual application In the middle, the text that is converted is multi-line, and the length of each line is not necessarily, so we also need to make a swipe before generating images in order to get a complete image size.

The following demonstrates the code that converts the image to the image.

// Function: Convert text into bitmap // aowner: Form Parameters // ATEXT: The text to be converted // AFONT: Text font // Abitmap: Translated bitmap object / / Date: 2003.12.15procedure TextTObitmap (AOwner: TObject; const aText: TStrings; aFont: TFont; ABitmap: TBitmap); var i: integer; iWidth, iHeight: integer; iCharHeight: integer; s: string; r: TRect; size: TSize; lblTemp: TLabel; Begin iWidth: = 0; IHEIGHT: = 0;

LBLTEMP: = TLABEL.CREATE (NIL); R.TOP :=0; try lbltemp.visible: = false; lbltemp.parent: = twinControl (aowner); lbltemp.font.assign (AFONT); Abitmap.canvas.brush. Style: = bsclear; Abitmap.canvas.pen.color: = RGB (0,0,0); Abitmap.canvas.brush.color: = RGB (255, 255, 255); Abitmap.canvas.Font.Assign (AFONT);

// The following code users get the maximum width and height of the text for i: = 0 to attext.count-1 do begin s: = atext.strings [i]; if s = '' THEN S: = ''; lbltemp.caption : = S;

GettextExtentPoint32 (lbltemp.canvas.handle, pchar (lbltemp.caption), lbltemp.gettextlen, size); if iWidth

// Get a height of a character GettextExtentPoint32 (lbltemp.canvas.handle, pchar ('), length); icharheight: = size.cy;

Abitmap.width: = iWidth; Abitmap.Height: = IHEIGHT; for i: = 0 to attext.count-1 do begin s: = atext.strings [i];

R.L.right: = 0; r.right: = Abitmap.width; R.Bottom: = R.BOTTOM ICHERHEIGHT;

Drawtext (Abitmap.canvas.Handle, Pchar (S), Length (S), R, 0); R.top:=R.top icHearHeight; end; finally lblTemp.free; end; end;

2003.12.15 Ling Li Software Studio http://china.wosens.net

转载请注明原文地址:https://www.9cbs.com/read-29821.html

New Post(0)