现想用XML来保存位图数据,位图数据是怎么写入XML文件中的!
例如:
<root>
<bmp>
  <name>pic1</name>
  <data>位图数据</data>
</bmp>
</root>
我想用data节点来保存位图,问题是我该如何从位图文件中读出数据,又如何写入XML中?入者有分,有代码者多100分!

解决方案 »

  1.   

    用base64编码转成字符串后再保存。
      

  2.   

    同意楼上;Bin->String :: String->Bin
      

  3.   

    unit Base64;interface
    uses EncdDecd,Graphics,Classes;
    function BitmapToString(Bitmap:TBitmap):String;
    function StringToBitmap(str:String):TBitmap;
    implementation
    function BitmapToString(Bitmap:TBitmap):String;
    var
      BitmapStream:TMemoryStream;
      strStream:TStringStream;
    begin
      BitmapStream:=TMemoryStream.Create;
      strStream:=TStringStream.Create('');
      Bitmap.SaveToStream(BitmapStream);
      BitmapStream.Position:=0;
      EncodeStream(BitmapStream,strStream);
      Result:=strStream.DataString;
      BitmapStream.Free;
      strStream.Free;
    end;function StringToBitmap(str:String):TBitmap;
    var
      BitmapStream:TMemoryStream;
      strStream:TStringStream;
    begin
      strStream:=TStringStream.Create(str);
      BitmapStream:=TMemoryStream.Create;
      DecodeStream(strStream,BitmapStream);
      BitmapStream.Position:=0;
      result:=TBitmap.Create;
      result.LoadFromStream(BitmapStream);
      BitmapStream.Free;
      strStream.Free;
    end;
    end.
      

  4.   

    同一楼上的几位,现在webservice中传送文件,soap协议传送的xml格式文件就是这样实现的。