请问下delphi中如何将指目录下的图片化成二进制流输出? Delphi / Windows SDK/API http://www.delphi2007.net/DelphiMultimedia/html/delphi_2006120714322474.html
请问下delphi中如何将指目录下的图片化成二进制流输出? 现在网上关于这块好像讲得都是关于发何人sql数据库中取。而我是想将目录下的图片化成二进制数据流,不知有哪位高手做过,指点一二,我不知怎么做起?
var S: TMemoryStream; begin S := TMemoryStream.Create; S.LoadFrom('目录\文件名'); end;
var S: TMemoryStream; begin S := TMemoryStream.Create; S.LoadFromFile('目录\文件名'); end;
楼上正解 按照楼上的,你要的结果是再把S输出就行了
那如何得到它的二进制码呢? { 0A544A504547496D616765693C0000FFD8FFE000104A46494600010200006400 640000FFEC00114475636B79000100040000002A0000FFEE002141646F626500 64C00000000103001003030609000018750000257500003C67FFDB0084000B08 080808080B08080B100A090A10130E0B0B0E1316111113111116151112121212 111515191A1B1A1915212124242121302F2F2F3036363636363636363636010C }
换成2进制代码?? 不会 帮顶 关注中
怎么输出呀大哥,换成二进制码...
这样好象可以,没测试,你去试试吧; var S: TMemoryStream; x: string; begin S := TMemoryStream.Create; S.LoadFromFile('目录\文件名'); SetLength(x, s.Size); move(s.memory^, x[1], s.size); s.free; 显示X; end;
流里面本身就是二进制码,你说的应该是如何显示二进制码
to zhang3652 非常感谢,我试过了,不行哦。 procedure TForm1.Button1Click(Sender: TObject); var GetString,filenamepath:string; astream:TMemoryStream; buffer:array of char; begin if OpenDialog1.Execute then begin filenamepath:=OpenDialog1.FileName; astream:=TMemoryStream.Create; astream.LoadFromFile(filenamepath); setlength(buffer,astream.size); move(astream.memory^,buffer[0],astream.Size); GetString:=string(buffer); Edit1.Text:= GetString; end; 得不到二进码
procedure TForm1.Button1Click(Sender: TObject); var S: TStream; B: TStream; I: Integer; C: Byte; D: string; begin B := TMemoryStream.Create; Image1.Picture.Bitmap.SaveToStream(B); B.Position := 0; S := TFileStream.Create('d:\111.txt', fmCreate); for I := 0 to B.Size - 1 do begin B.Read(C, 1); D := IntToHex(C, 2); S.Write(D[1], 2); if (I <> 0) and ((I mod 32) = 0) then begin D := #13 + #10; S.Write(D[1], 2); end; end; B.Free; S.Free; end;
按搂住的要求应该把 Image1.Picture.Bitmap.SaveToStream(B); 改为 TMemoryStream(B).LoadFromFile('目录\文件名');
呵呵,谢谢楼上两位,我试试。
呵呵,搞定了。。 procedure TForm1.Button2Click(Sender: TObject); var S: TStream; B: TStream; I: Integer; C: Byte; D: string; begin B := TMemoryStream.Create; // Image1.Picture.Bitmap.SaveToStream(B); TMemoryStream(B).LoadFromFile('E:\Delphi程序\Picture\jz12.jpg'); B.Position := 0; S := TFileStream.Create('d:\111.txt', fmCreate); for I := 1 to B.Size do begin B.Read(C, 1); D := IntToHex(C, 2); S.Write(D[1], 2); if ((I mod 32) = 0) then begin D := #13 + #10; S.Write(D[1], 2); end; end; B.Free; S.Free; end;
呵呵,搞定了。。 ============================================================= 你提问表达方式有问题,这不是二进制流输出,应该叫二进制流的文本格式输出,你早说清楚,答案早出来了.
|
请发表评论