Delphi establishes a function of specifying a size font and reading the font marked information.

zhaozj2021-02-17  44

Delphi establishes a function of specifying a size font and reading the font marked information.

Author: ThermometerEmail: webmaster@daheng-image.com

Since the hardware is to be controlled, the vector's Chinese characters need to be converted into the dot matrix information to write EPROM or display it on the LCD screen, so use the Delphi to write the following function, you can convert the specified Chinese characters (two characters) into a point-in information Save to the file, each point corresponds to a binary bit, there is a text message to 1, otherwise 0.

This function can generate a specified size of Chinese characters and readable to files to files.

Such as ConvertTomatrix (Pchar (North '), 6, 18,' Font.dat 'will generate 12 * 18 o'clock file font.dat, where the word model information of the Chinese characters' North' is saved. The file format is from top to bottom, first line, as shown below, the first line is saved to 00 00, the second line is 90 00 (all 16), the remaining row push)

// Transform a Chinese character as a point of information. The parameter text is a Chinese character, and ChrWidth is a character wide. The Chinese characters are two characters size, so if they want to generate a wide 12 Chinese characters, chrwidth is 6, and ChrWidth is currently 8, because most hardware uses the dot information is 16 The following chrheight is the high Chinese characters, and SaveFileName is the file name that saves the Chinese character. function ConvertToMatrix (Text: PChar; ChrWidth, ChrHeight: Byte; SaveFileName: Pchar): Bool; type PBITMAPINFO = ^ TBitmapInfo; var TempBmp: TBitmap; lpvSBits, lpvDBits: Pchar; dOffset, sOffset: integer; DC: HDC; TheFont: HFont ;

BMIINFO: PbitmapInfo; DS: TDIBSECTION; BMIBUF: Array [0..2047] of byte;

I, J: Integer; // loop control

WDATA: WORD; / / Save the dot matrix information for each line of the font, up to 16 digits, less than 16 bits ignore the extra high

MemoryStream: TmemoryStream;

Begin // is greater than one word exits if Length (text)> 2 Then Begin showMessage ('Please translate a Chinese character!'); result: = false; exit; End; // Parameter reasonably if (chrwidth = 0) or (chrheight) or (chrheight = 0) or (SaveFileName = '') THEN BEGIN SHOWMESSAGE ('Parameter Error!'); Result: = False; EXIT; End; // Setting Stream MemoryStream: = TMEMORYSTREAM.CREATE; / / Establish temporary file Tempbmp: = Tbitmap .Create; // set to 256 color tempBmp.pixelformat: = pf8bit; // Setting the diagram width Tempbmp.Width: = chrwidth * length (text); // Setting the graph high Tempbmp.Height: = chrheight; // BMP file obtained HDC DC: = TempBmp.Canvas.Handle; // set logical font TheFont: = CreateFont (ChrHeight, ChrWidth, 0, 0, 400, 0, 0, 0, GB2312_CHARSET, Out_Default_Precis, Clip_Default_Precis, Default_Quality, Default_Pitch OR FF_SCRIPT , 'script'); // Specify the font to DC SelectObject (DC, thefont); // Write the specified string Textout (DC, 0, 0, pchar (text), length (text)); // Release the logic font DeleteObject (thefont);

// Get information to Bmp lpvSBits BMIInfo: = PBITMAPINFO (@BMIbuf); // allocate memory lpvSBits: = AllocMem (TempBmp.Width * TempBmp.Height); lpvDBits: = AllocMem (TempBmp.Width * TempBmp.Height); // Establish a program screen compatible DC DC: = CREATECOMPATIBLEDC (0); // Returns the specified BMP information to save getObject (Tempbmp.Handle, SizeOf (DS), @ds); // Read the head information Bmiinfo.bmiheader: = DS.DSBMIH; // Read Dib getDibits (DC, Tempbmp.Handle, 0, DS.DSBMIH.BIHEIGHT, DS.DSBMIH.BIHEIGHT, DIB_RGB_COLORS); // Inverted Image for i: = 0 to Tempbmp.Height-1 DO Begin Soffset: = I * Tempbmp.width; Doffset: = (Tempbmp.Height-i-1) * Tempbmp.Width; CopyMemory (LPVDBITS DOFFSET, LPVSBITS SOFFSET, TEMPBMP.WIDTH); END; // Save File for i : = 0 to Tempbmp.height-1 Do Begin WData: = 0; for J: = 0 to Tempbmp.Width-1 Do Begin //showMessage (ITSTR (ORD ((LPVDBITS ITEMPBMP.WIDTH J )^) )); If ORD ((LPVDBITS I * TEMPBMP.WIDTH J) ^) = 0 THEN Begin WData: = (WData SHL 1) OR 1; Else Begin WData: = (WData SHL 1) OR 0; END; End; MemoryStream.write (WDATA, SIZEOF (WDATA)); E Nd; memorystream.savetofile (SaveFileName); MemoryStream.free; // Tempbmp.savetofile ('Temp.Bmp') can be deleted, the purpose of the 'Temp.Bmp' file is just to look at TempBMP.Savetofile ('Temp.BMP') ); Tempbmp.Free; FreeMem (lpvsbits); FreeMem (lpvdbits); result: = true;

END;

Attachment: This article is originally original, if you have changed the program in use, please send the author to Webmaster@daheng-image.com;

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

New Post(0)