给一段我的代码给你,自个看吧,可以解决你的问题:
procedure TFrmMain.DecodeData(allStr: AnsiString);
var theValue,imageStr,deviceID:String;
i,j:Integer;
imageDateTime: TDateTime ;
ms_AX_1: TMemoryStream;
jp_AX_1:TJPEGImage ;
strList_1:TStringList;
begin
theValue:= getValue(allStr,ptr_xmlin[1]);
if not ((theValue='0') or (theValue='4')) then
begin
if theValue='2' then //设备建立连接
updateDeviceState(allStr);
Exit;
end;
deviceID:=getValue(allStr,ptr_xmlin[4]);
theValue:=getValue(allStr,ptr_xmlin[9]);
theValue :=copy(theValue,1,4)+'-'+copy(theValue,5,2)+'-'+copy(theValue,7,2)+' '+
copy(theValue,9,2)+':'+copy(theValue,11,2)+':'+copy(theValue,13,2);
imageDateTime:=StrToDateTime(theValue);
theValue:=getValue(allStr,ptr_xmlin[8]);
theValue:=copy(theValue,10 ,length(theValue)-12);
strList_1:=TStringList.Create;
strList_1.Text:=theValue;
j:=strList_1.Count-1;
for i :=0 to j do
begin
if i=j then
imageStr:=imageStr+copy(strList_1,1,length(strList_1)-1)
else
imageStr:=imageStr+copy(strList_1,1,76);
end;
strList_1.Free ;//:=nil;
with ADOQImageAX do
begin
Close;
Open;
Append;
FieldByName('device_ID').AsString:=deviceID;
FieldByName('image_Time').AsDateTime:=imageDateTime;
FieldByName('image_data').AsString:=DecodeBase64(imageStr);
end;
try
ms_AX_1:=TMemoryStream.Create() ;
jp_AX_1:=TJPEGImage.Create() ;
ms_AX_1.Clear;
jp_AX_1.Empty;
{
ms_AX.Clear;
jp_AX.Empty;
}
//ImageAX.Picture.Free;
TBlobField(ADOQImageAX.FieldByName('image_data')).SaveToStream(ms_AX_1);
ms_AX_1.Seek(0,soFromBeginning);
jp_AX_1.LoadFromStream(ms_AX_1);
ImageAX.Picture.Bitmap.Assign(jp_AX_1);
ImageAX.Picture.Bitmap.Canvas.TextOut(0,0,DatetimeToStr(imageDateTime));
Sleep(1);
jp_AX_1.Assign(ImageAX.Picture.Bitmap);
ms_AX_1.Position:=0;
jp_AX_1.SaveToStream(ms_AX_1);
TBlobField(ADOQImageAX.FieldByName('image_data')).LoadFromStream(ms_AX_1);
ADOQImageAX.Post;
MemoAccept.Lines.Add(DateTimeToStr(now)+'==>'+deviceID+':图像来了!');
finally
if ADOQImageAX.State in [dsInsert] then
ADOQImageAX.Cancel;
//ms_AX_1:=nil;
ms_AX_1.Free ;
jp_AX_1.Free;
//jp_AX_1:=nil;
end;
end;