我需要将一个字符串直接打印到打印机中,
我通过搜索找到了这个代码
uses WinSpool, Printers
type
TDoc_Info_1 = record
pDocName: pChar;
pOutputFile: pChar;
pDataType: pChar;
end;
procedure PrintSimpleText(sPrinter, sText: String);
var
sTitle: String;
hPrinter: THandle;
PrnDocInfo: TDoc_Info_1;
lst: TStringList;
i: Integer;
n: Cardinal;
sTextLine: String;
bFound: Boolean;
begin
lst := TStringList.Create;
try
lst.Text := sText; //with CRLF
//new doc
sTitle := 'Raw print';
ZeroMemory(@PrnDocInfo, SizeOf(TDoc_Info_1));
PrnDocInfo.pDocName := PChar(sTitle);
PrnDocInfo.pDataType := 'RAW';
//find printer (if is installed in windows)
bFound := False;
for i:=1 to Printer.Printers.Count do
begin
if Pos(sPrinter, Printer.Printers.Strings[i-1])>0 …Run Code Online (Sandbox Code Playgroud) 我需要转换画布的所有像素
在谷歌快速搜索后发现此功能
但是工作不正确,但似乎必须工作得很好!!
function RGBBitmapTo1Bit(OriginalBitmap : TBitmap) : TBitmap;
var
x, y : integer;
begin
result := TBitmap.Create;
result.width := OriginalBitmap.width;
result.height := OriginalBitmap.height;
for x := 1 to OriginalBitmap.width do
for y := 1 to OriginalBitmap.height do
begin
result.Canvas.Pixels[x, y] := clBlack;
end;
end;
Run Code Online (Sandbox Code Playgroud)
此功能不对文件进行任何更改
例如,我这样使用
procedure TForm1.Button2Click(Sender: TObject);
var
imgf : TBitmap;
begin
if od1.Execute then
begin
imgf := TBitmap.Create;
imgf.LoadFromFile(od1.FileName);
RGBBitmapTo1Bit(imgf);
imgf.SaveToFile(ExtractFilePath(od1.FileName)+'test.bmp');
end;
Run Code Online (Sandbox Code Playgroud)
但输出和输入文件是一样的!
我怎样才能正确地为像素分配颜色!?
我必须设置一个tcp服务来处理一些客户端请求
所有请求都以长度为1099字节的十六进制字符串包的形式出现,并且都以开头00D0和结尾00000000
procedure TForm2.IdTCPServer1Execute(AContext: TIdContext);
begin
AContext.Connection.IOHandler.ReadBytes(data, 1099, False);
RStr:='';
for I := 0 to length(data)-1 do
RStr := RStr + chr(data[i]);
if(copy(RStr,1,4)='00D0') and (copy(RStr,1091,8)='00000000') then
begin
Memo14.Lines.Add( 'Frame added to database.' );
end
else
begin
Memo14.Lines.Add( 'error invalid Frame ...' );
end;
end;
Run Code Online (Sandbox Code Playgroud)
服务器接收到1099字节数据包,但仅error invalid Frame ...显示。
我的代码有什么问题!?
PS:客户端正在向服务器连续发送数据,这意味着客户端从第三方接收数据并发送到服务器,因此可能不是从数据包的第一位开始发送数据!所以我必须先丢弃一些数据才能到达数据包00D0!