沙发,在看...
以前做过数据用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。