Source: A function in Delphi to create a specified size font and read the bitmap information of the font
A function in Delphi to create a specified size font and read the bitmap information of the font
Thermometer Email: [email protected]
Because to control the hardware, you need to convert the vector characters into lattice information to write to EPROM or display on the LCD screen, so the following functions are written by Delphi, you can convert a specified Chinese character (two characters) to the bitmap information saved to a file, each point corresponds to a bits, there is a text message that bit is 1, Otherwise, it is 0.
At present, the function can generate a specified size of Chinese characters and can read the matrix font information saved to the file.
such as Converttomatrix (Pchar (' North '), 6,18, ' Font.dat ') will generate 12*18 lattice file Font.dat, which holds the character information of the Chinese characters ' north '. The file format is from top to bottom, followed by columns, such as the first row is saved as 00 00, the second row is 90 00 (all 16, the remaining rows and so on)
//transform a Chinese character into a lattice information. The parameter text is a Chinese character, Chrwidth is a character justifies, the Chinese character is two characters, so if you want to generate a character with a width of 12, then chrwidth for the 6,chrwidth is currently up to 8, because most of the hardware uses the dot matrix information is 16 below Chrheight is the Chinese character's high , Savefilename is the file name that holds the bitmap information for the Chinese character. functionConverttomatrix (Text:pchar; Chrwidth,chrheight:byte; Savefilename:pchar): Bool;typePbitmapinfo=^tbitmapinfo;varTempbmp:tbitmap; Lpvsbits,lpvdbits:pchar; Doffset,soffset:integer; DC:HDC; Thefont:hfont; Bmiinfo:pbitmapinfo; Ds:tdibsection; BMIBUF:Array[0..2047] ofbyte; I,j:integer;//Loop ControlWdata:word;//Save the bitmap information for each line of the font, up to 16 bits, less than 16 bits ignoring the extra highMemorystream:tmemorystream;begin //More than one word to exit ifLength (Text) >2 Then beginShowMessage ('Please convert a Chinese character! '); Result:=False; Exit; End; //parameter Reasonable no if(chrwidth=0)or(chrheight=0)or(Savefilename ="') Then beginShowMessage ('parameter Error! '); Result:=False; Exit; End; //Create a Streammemorystream:=tmemorystream.create; //Create a temporary filetempbmp:=tbitmap.create; //set to 256 colorstempbmp.pixelformat:=Pf8bit; //Set Chart widthTempbmp.width:=chrwidth *Length (Text); //Set Chart Heighttempbmp.height:=Chrheight; //get BMP File hdcdc:=TempBmp.Canvas.Handle; //Create a logical fontThefont: = CreateFont (Chrheight,chrwidth,0,0, -,0,0,0, Gb2312_charset, Out_default_precis, Clip_default_precis, default_quality, Default_pitch OR FF_SCRIPT,'Script'); //Specify font to DCSelectObject (Dc,thefont); //writes the specified stringTextOut (DC,0,0, Pchar (text), Length (text)); //Releasing logical FontsDeleteObject (Thefont); //get BMP information to Lpvsbitsbmiinfo:=Pbitmapinfo (@BMIbuf); //Allocating MemoryLpvsbits:=allocmem (tempbmp.width*tempbmp.height); Lpvdbits:=allocmem (tempbmp.width*tempbmp.height); //Setting up a program screen compatible DCDC: = CreateCompatibleDC (0); //returns the specified BMP information to the DS in the SaveGetObject (Tempbmp.handle, SizeOf (DS), @DS); //Read header informationbmiinfo.bmiheader:=Ds.dsbmih; //read in DibGetDIBits (DC, Tempbmp.handle,0, Ds.dsbmih.biheight,lpvsbits, bmiinfo^, dib_rgb_colors); //Inverted Image fori:=0 totempbmp.height-1 Do beginSoffset:=i*Tempbmp.width; Doffset:= (tempbmp.height-i-1)*Tempbmp.width; CopyMemory (Lpvdbits+doffset,lpvsbits+soffset,tempbmp.width); End; //Save File fori:=0 totempbmp.height-1 Do beginWdata:=0; forj:=0 totempbmp.width-1 Do begin //ShowMessage (IntToStr (ord (lpvdbits+i*tempbmp.width+j) ^ )); ifOrd ((lpvdbits+i*tempbmp.width+j) ^) =0 Then beginWdata:= (wdataSHL 1) OR1; End Else beginWdata:= (wdataSHL 1) OR0; End; End; Memorystream.write (wdata,sizeof (wdata)); End; Memorystream.savetofile (Savefilename); Memorystream.free;//tempbmp.savetofile (' temp.bmp ') can be deleted, save the ' temp.bmp ' file for comparison purposes onlyTempbmp.savetofile ('temp.bmp'); Tempbmp.free; Freemem (lpvsbits); Freemem (lpvdbits); Result:=True;End;
Attached: This article is all original content, if you use in the program made changes please send the author a point [email protected]; Please note that the original author is thermometer and write clearly the original email, thank you.
A function that establishes a specified size font and reads the lattice information of the font in Delphi (GO)