如何从二制流数据中加载图形?
Delphi开发|黄洪辉|2018-06-14 10:22
-
回答:
主要用到函数说明:
_DMxDrawX::ReadBinStream
从二制流数据中加载图形,详细说明如下:
参数 说明 VARIANT varBinArray
二制流数据,是个byte数组
BSTR sPassword
图纸密码.没有密码,传空字符串
LONG lReadContent
加载内容,如果全部加载,传16777215,十六进制0xFFFFFF
Delphi代码实现如下:
function OleToMStream(OV:OleVariant): TMemoryStream; var Data: PByteArray; Size: integer; beginResult:=TMemoryStream.Create; try Size:=VarArrayHighBound(OV,1)-VarArrayLowBound(OV,1)+1; Data:=VarArrayLock(OV); try Result.Position:=0; Result.WriteBuffer(Data^,Size); finally VarArrayUnlock(OV); end; except Result.Free;Result:=nil; end; end; function MStreamToOle(Strm:TMemoryStream): OleVariant; var Data: PByteArray; beginResult:= VarArrayCreate([0, Strm.Size - 1], varByte); Data:= VarArrayLock(Result); try Strm.Position := 0; Strm.ReadBuffer(Data^, Strm.Size); finally VarArrayUnlock(Result); end; end; procedure TForm2.Button6Click(Sender: TObject); var aryData:OleVariant; memStream : TMemoryStream ; aryReadData: OleVariant; begin // 写到内存流 MxDrawX1.WriteBinStream(aryData,'',23); memStream := OleToMStream(aryData); // 从内存流加载 aryReadData := MStreamToOle( memStream); MxDrawX1.ReadBinStream(aryData,'',23); end;