www.mxdraw.com
内容索引主面
前一个向上下一个
_DMxDrawX::ReadBinStream 方法

从二制流数据中加载图形.

IDL
[id(116), helpstring("method ReadBinStream")]
VARIANT_BOOL ReadBinStream(VARIANT varBinArray, BSTR sPassword, LONG lReadContent);
参数 
说明 
VARIANT varBinArray 
二制流数据,是个byte数组。 
BSTR sPassword 
图纸密码.没有密码,传空字符串 
LONG lReadContent 
加载内容,如果全部加载,传16777215,十六进制0xFFFFFF 

成功返回True

例如:VB调用例程

            Dim aryData     As Variant
            MxDrawX1.WriteBinStream aryData, "", 23

            Dim ln As Long
            ln = UBound(aryData)

            ReDim sbyte(0 To ln) As Byte

            Dim str$
            For i = 0 To ln
                sbyte(i) = aryData(i)
                'str = str & " " & (aryData(i))
            Next

            'MsgBox str

            'MxDrawX1.ReadBinStream aryData, "", 16777215

            MxDrawX1.ReadBinStream sbyte, "", 16777215

例如: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;

例如: C#代码.

                    string sFileName = "G:\12345.dwg";
                    //axMxDrawX1.SaveDwgFile(sFileName);

                    FileStream fileStream = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
                    BinaryReader binaryReader = new BinaryReader(fileStream);
                    byte[] mybyte = binaryReader.ReadBytes((int)fileStream.Length);

                    axMxDrawX1.NewFile();

                    axMxDrawX1.ReadBinStream(mybyte, "", 16777215);

例如: JS代码.,例子,参考doc/Demo.rar

    //服务器后台代码,返回前台二进制流数据.
    public JsonResult change()
    {
     FileStream fileStream = new FileStream(Server.MapPath(fileName), FileMode.Open, FileAccess.Read, FileShare.Read);
     BinaryReader binaryReader = new BinaryReader(fileStream);
     byte[] mybyte = binaryReader.ReadBytes((int)fileStream.Length);

     return Json(mybyte, JsonRequestBehavior.AllowGet);
    }

    // 前台客服端代码:
    function Bytes2Str(arr) {

     var str = "";

     for (var i = 0; i < arr.length; i++) {

         var tmp = arr[i].toString(16);

         if (tmp.length == 1) {

             tmp = "0" + tmp;

         }

         str += tmp;

     }

     return str;

   }
    function InitMxDrawX()
 {
     var mxOcx = document.getElementById("MxDrawXCtrl");
     if (mxOcx) {


     if (!mxOcx.IsIniting()) {
         clearInterval(mxtime);
    
             $.ajax({
                 url: '@Href("~/Home/change")',
                 success: function (text) {
                     
                     alert(typeof (text));

                    var str = Bytes2Str(text);

                    mxOcx.NewFile();
                     mxOcx.ReadBinStream(str, "", "16777215");
                 },
                 error: function () {
                     alert("失败");

                 }
             });
         //mxOcx.OpenWebDwgFile("http://192.168.0.13/DWG/后沟.dwg");
     }
     }
 }
 mxtime = setInterval(InitMxDrawX, 100);
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!