照片信息以Base64存到了XML文件中,我还想把还原出来,存为图片文件。进来看看。
http://www.delphi2007.net/DelphiVCL/html/delphi_20061225112307135.html
<?xml version="1.0"?>
<root>
<photo xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">/9j/4AAQSkZJRgABAgIAJwAnAAD/4QALUElDAAIgIwEA/8AACwgAaABOAQERAP/bAEMAEAsM
DgwKEA4NDhIREBMYKBoYFhYYMSMlHSg6Mz08OTM4N0BIXE5ARFdFNzhQbVFXX2JnaGc+TXF5
cGR4XGVnY//EAEkAAAMBAQEBAAAAAAAAAAAAAAIDBAUBAAYQAAICAQMDAgQFAwUAAAAAAAEC
AAMRBCExEkFRE2EFInGBFDKR0fAzobFCUmJy8f/aAAgBAQAAPwDa1OoV7D1K69gcbSR2auzA
rZvcD6ye1LLLc9D57DH+IVdl6YQIw24APtGmy/qIHq7eAduZPY1l7dK9bEdsEkSIgq5U5B8E
YxGoCrZDb+03Ph+s6wK7D8w2B8zRDDEyfSDVEHO89aQtyoVYk8Y+851H8b6eGzntx9oKufxv
R8xb+3Ah5FtL2gkMFKtFaVU0yetnBY4BPjeT/FaPT1BsAwH/AMyFWPePS5ldWBAx4n0WmtF1
CuDzIRqK2KhmKkf7/tEO1z6lgjhhyMGVCu0Hq+bPnME1Wl+sEhuM5gfhrB1DqYB+feLvq1HQ
ALCQN8GRai+9x0WtnG+JLk5A2hKe+d5t/B7Sa3QnIByIT1qWCsO+D/bmJQJTeO2eJoeoAMYP
8zC+RsAHeEwwOIiy2pPzsombq3qu2rG/mRjTux6QuD9Iv0iGxwRNj4PQymxs7HaV6lQl5+XO
TnPPiIuQLYGI8YlOU6cEHj795301JDKcyisda4O495Fq9NUH6mWIS2hWCrVv7CUIK7dwo28i
Y+uqNerYDvvN34fUa9OoPJ3P1h6pc3Icfz3i3rDOue2IZqBGDOlOkH3jauIvVViwCTV6ZVfr
wM+ZQqBRsAJDrNKbtRWy9uf1mnWMLiHdWMqT2MAKhbI7QiNuIttz/PeNTOIuz8wnMT0Hp+bM
conXs6hxI/XKORG/iMLJLtZ6ZJ6TmMp+IK6/kbPjEYt/rcoVxGzwhDidyRxBkd2zxNt3QsT6
qWHciU1mtQCCI5bE7MPsYxbAw2OYY3h9pwnA8z0m1SZTI5Ez2+fniINQDZ6Y1OhdiHPtKa60
bhSI+tBXxKEOYYnTxOYOMiQa220kJUuR/qOZCS1T/ONjHI6HuDH1tVtxHhkxtie+ZvyqcecS
GrVPTr2SzIRj3msrZxOniZ7X2MoJcAeMfSCFBGQEz/0i9TQbDyBv+8JNHWBgg5Pv9I6nSIu+
x27yj0ayeN48DAAkFwX1mJVSPcZ8TlWo9IKDnBPeULq6js2Vx5mfUQigMWJ8/pDFybZL8e37
Txb1HBUkD/2VBQD+YD7w1AA/qL+v0hq1YOeoTzaisd84kNltVlhHV0n/AJbeJzDYGBkD9pHq
1LWZ48/qZ//ZAA==</photo>
</root>
Base64编码如上,大家帮我还原一下。谢谢!
沙发,在看...
以前做过数据用BASE64转换,等我试试...
Indy就有的
yi10000()
等你。
ly_liuyang
我也知道有,但不会用啊。。
uses EncdDecd, XMLDoc, xmldom;
procedure TForm1.Button1Click(Sender: TObject);
var
vXMLDocument: TXMLDocument;
vDOMNodeList: IDOMNodeList;
vDOMNode: IDOMNode;
I, J: Integer;
S: string;
begin
vXMLDocument := TXMLDocument.Create('c:\temp\temp.xml');
vDOMNodeList := vXMLDocument.DOMDocument.getElementsByTagName('root');
if Assigned(vDOMNodeList) and (vDOMNodeList.length > 0) then
begin
for I := 0 to vDOMNodeList.length - 1 do
begin
vDOMNode := vDOMNodeList.item[I];
if vDOMNode.hasChildNodes then
begin
vDOMNode := vDOMNode.firstChild;
if SameText(vDOMNode.nodeName, 'photo') then
begin
if vDOMNode.hasChildNodes then
begin
vDOMNode := vDOMNode.firstChild;
if SameText(vDOMNode.nodeName, '#text') then
begin
S := DecodeString(vDOMNode.nodeValue);
if Length(S) > 0 then
with TMemoryStream.Create do try
Write(S[1], Length(S));
SaveToFile('c:\temp\temp.jpg');
finally
Free;
end;
end;
end;
end;
end;
end;
end;
vXMLDocument.Free;
end;
function Base64Decode(const s: string): string;
var
Coder: TIdBase64Decoder;
begin
Coder := TIdBase64Decoder.Create(nil);
try
Coder.AddCRLF := False;
Coder.UseEvent := False;
Coder.Reset;
Coder.CodeString(s);
Result := Copy(Coder.CompletedInput, 3, MaxInt);
finally
FreeAndNil(Coder);
end;
end;
mms???
谢谢 zswang(伴水清清)(专家门诊清洁工) 。成功了!
以下是VB代码。不知道,能否也转到delphi中?
Private Sub Command2_Click()
Dim xmlDoc As New MSXML.DOMDocument
xmlDoc.Load App.Path & "\@CI56789000A.trm"
Dim iStm As ADODB.Stream
Set iStm = New ADODB.Stream
With iStm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write xmlDoc.selectSingleNode("root").selectSingleNode("photo").nodeTypedValue
.SaveToFile App.Path & "\test1.jpg"
End With
End Sub
//早说你有这样的代码,我也不用这样费劲了
uses ComObj;
const
adModeUnknown = $00000000;
adModeRead = $00000001;
adModeWrite = $00000002;
adModeReadWrite = $00000003;
adModeShareDenyRead = $00000004;
adModeShareDenyWrite = $00000008;
adModeShareExclusive = $0000000C;
adModeShareDenyNone = $00000010;
const
adTypeBinary = $00000001;
adTypeText = $00000002;
adStateClosed = $00000000;
adStateOpen = $00000001;
adStateConnecting = $00000002;
adStateExecuting = $00000004;
adStateFetching = $00000008;
procedure TForm1.Button1Click(Sender: TObject);
var
vDOMDocument: OleVariant;
vStream: OleVariant;
vAppPath: string;
begin
vAppPath := ExtractFilePath(ParamStr(0));
vDOMDocument := CreateOleObject('MSXML.DOMDocument');
vDOMDocument.Load(vAppPath + '@CI56789000A.trm');
vStream := CreateOleObject('ADODB.Stream');
vStream.Mode := adModeReadWrite;
vStream.Type := adTypeBinary;
vStream.Open;
vStream.Write(vDOMDocument.selectSingleNode('root').selectSingleNode('photo').nodeTypedValue);
if FileExists(vAppPath + 'test1.jpg') then DeleteFile(vAppPath + 'test1.jpg');
vStream.SaveToFile(vAppPath + 'test1.jpg');
vStream := NULL;
vDOMDocument := NULL;
end;
呵呵,谢谢zswang。