当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader类代码示例

本文整理汇总了C#中BinaryReader的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader类的具体用法?C# BinaryReader怎么用?C# BinaryReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BinaryReader类属于命名空间,在下文中一共展示了BinaryReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendFileToPrinter

	public static bool SendFileToPrinter( string szPrinterName, string szFileName )
	{
		// Open the file.
		FileStream fs = new FileStream(szFileName, FileMode.Open);
		// Create a BinaryReader on the file.
		BinaryReader br = new BinaryReader(fs);
		// Dim an array of bytes big enough to hold the file's contents.
		Byte []bytes = new Byte[fs.Length];
		bool bSuccess = false;
		// Your unmanaged pointer.
		IntPtr pUnmanagedBytes = new IntPtr(0);
		int nLength;

		nLength = Convert.ToInt32(fs.Length);
		// Read the contents of the file into the array.
		bytes = br.ReadBytes( nLength );
		// Allocate some unmanaged memory for those bytes.
		pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
		// Copy the managed byte array into the unmanaged array.
		Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
		// Send the unmanaged bytes to the printer.
		bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
		// Free the unmanaged memory that you allocated earlier.
		Marshal.FreeCoTaskMem(pUnmanagedBytes);
		return bSuccess;
	}
开发者ID:marioricci,项目名称:erp-luma,代码行数:26,代码来源:Class2.cs

示例2: btnGuardarNotificacion_Click

    protected void btnGuardarNotificacion_Click(object sender, EventArgs e)
    {
        String textoValidacion = validarNotificacion(false);
        if (textoValidacion.Equals(""))
        {
            Stream fs = upFileNotificacion.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);

            ARCHIVO archivo = new ARCHIVO();
            archivo = archivo.addArchivo(Path.GetFileName(upFileNotificacion.PostedFile.FileName),
                                         Path.GetExtension(upFileNotificacion.PostedFile.FileName).Substring(1), bytes);

            if (archivo.ARCHIVOID != 0)
            {
                NOTIFICACION notificacion = new NOTIFICACION();
                notificacion.addNotificacion(txtNombreNotificacion.Text, txtDescripcionNotificacion.Text, archivo.ARCHIVOID,
                                             Convert.ToInt32(lblInstitucionId.Text));
                cargarNotificaciones();
                lblSucess.Text = "Se creo Correctamente la Notificacion";
                pnlSucess.Visible = true;
            }
            else
            {
                lblError.Text = "El archivo es demasiado pesado";
                pnlError.Visible = true;
            }

        }
        else
        {
            lblError.Text = textoValidacion;
            pnlError.Visible = true;
        }
    }
开发者ID:fabianpsilvam,项目名称:instituciones,代码行数:35,代码来源:Notificacion.aspx.cs

示例3: Read

    /// <summary>
    /// Reads from the provided file name all parameters and data for a
    /// heightmap.  If the data for the heightmap does not exist, then
    /// no data is written to the provided texture.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> that will store read-in parameters.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> that will store read-in parameters for
    /// <see cref="CloudFractal" />.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" />  that will store read-in parameters for
    /// <see cref="WorleyNoise" />.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Read(string fileName, ref NormalOptions no,
	                        ref CloudOptions co, ref VoronoiOptions vo,
							ref Texture2D tex)
    {
        using(BinaryReader r = new BinaryReader(File.OpenRead(fileName)))
        {
            no.size = r.ReadInt32();
            no.seed = r.ReadInt32();
            no.cloudInf = r.ReadSingle();
            no.voronoiInf = r.ReadSingle();
            no.useThermalErosion = r.ReadBoolean();
            no.useHydroErosion = r.ReadBoolean();
            no.showSeams = r.ReadBoolean();

            co.upperLeftStart = r.ReadSingle();
            co.lowerLeftStart = r.ReadSingle();
            co.lowerRightStart = r.ReadSingle();
            co.upperRightStart = r.ReadSingle();

            vo.metric = (DistanceFunctions.DistanceMetric)r.ReadInt32();
            vo.combiner = (CombinerFunctions.CombineFunction)r.ReadInt32();
            vo.numberOfFeaturePoints = r.ReadInt32();
            vo.numberOfSubregions = r.ReadInt32();
            vo.multiplier = r.ReadSingle();

            tex.Resize(no.size, no.size);
            int bLeft = (int)(r.BaseStream.Length - r.BaseStream.Position);
            if(bLeft > 0)
                tex.LoadImage(r.ReadBytes(bLeft));
        }
    }
开发者ID:seflopod,项目名称:EarthMake,代码行数:53,代码来源:HeightMapSerializer.cs

示例4: Main

    public static void Main() {
        byte[] bytes;

        var values = new long[] {
            0, 1, 0xFFFF, 0xFF00FF00FF00L, 12345678901234L, -0xFFFF, -0xFF00FF00FF00L
        };

        long length;

        using (var ms = new MemoryStream())
        using (var bw = new BinaryWriter(ms)) {
            foreach (var value in values) {
                bw.Write(value);
                Console.WriteLine(value);
            }

            bw.Flush();
            length = ms.Position;

            bytes = ms.GetBuffer();
        }

        Util.PrintByteArray(bytes, (int)length);

        using (var ms = new MemoryStream(bytes, false))
        using (var br = new BinaryReader(ms)) {
            for (int i = 0; i < values.Length; i++) {
                var value = br.ReadInt64();
                Console.WriteLine(value);
            }
        }
    }
开发者ID:GlennSandoval,项目名称:JSIL,代码行数:32,代码来源:Int64Serialization.cs

示例5: LoadTable

	public override void LoadTable(string _path)
	{		
		if ((null != AssetbundleManager.Instance && true == AssetbundleManager.Instance.useAssetbundle) || true == AsTableManager.Instance.useReadBinary) 
		{
			// Ready Binary
			TextAsset textAsset = ResourceLoad.LoadTextAsset (_path);
			MemoryStream stream = new MemoryStream (textAsset.bytes);
			BinaryReader br = new BinaryReader (stream);

			int nCount = br.ReadInt32 ();

			for (int i = 0; i < nCount; i++) {
				Tbl_SynDisassemble_Record record = new Tbl_SynDisassemble_Record (br);
					m_recordList.Add (record);		
			}

			br.Close ();
			stream.Close ();				
		} 
		else 
		{
			XmlElement root = GetXmlRootElement(_path);
			XmlNodeList nodes = root.ChildNodes;
			
			foreach(XmlNode node in nodes)
			{
				Tbl_SynDisassemble_Record record = new Tbl_SynDisassemble_Record((XmlElement)node);			
				m_recordList.Add( record );
			}		
		}
	}		 
开发者ID:ftcaicai,项目名称:ArkClient,代码行数:31,代码来源:Tbl_SynDisassembleTable.cs

示例6: Read1

    public static Recording Read1(BinaryReader reader)
    {
        // Create a recording
        Recording rec = new Recording();

        // Read the flagged value
        rec.flagged = reader.ReadBoolean();

        // Read the fps
        rec.fps = reader.ReadInt32();

        // Read the score.
        rec.score.Read(reader);

        // Read the level name
        rec.levelName = reader.ReadString();

        // Read all the states.
        int stateCount = reader.ReadInt32();
        for (int i = 0; i < stateCount; ++i)
        {
            State state = new State();
            state.Read(reader);
            rec.states.Add(state);
        }

        return rec;
    }
开发者ID:mokacao,项目名称:StellarSwingClassic,代码行数:28,代码来源:Recording.cs

示例7: ApplyChanges

    public override void ApplyChanges(Stream stream)
    {
        using (var reader = new BinaryReader(stream))
        {
            var stamp = reader.ReadInt64();
            var x = reader.ReadSingle();
            var y = reader.ReadSingle();
            var z = reader.ReadSingle();

            var vx = reader.ReadSingle();
            var vy = reader.ReadSingle();
            var vz = reader.ReadSingle();

            var rx = reader.ReadSingle();
            var ry = reader.ReadSingle();
            var rz = reader.ReadSingle();
            var rw = reader.ReadSingle();

            if (LastChanged < stamp)
            {
                LastChanged = stamp;
                Stormancer.MainThread.Post(() =>
                {
                    this.transform.position = new Vector3(x, y, z);
                    PlayerRigidbody.velocity = new Vector3(vx, vy, vz);
                    this.transform.rotation = new Quaternion(rx, ry, rz, rw);
                });
            }
        }
    }
开发者ID:songotony,项目名称:RType-Client,代码行数:30,代码来源:LocalPlayer.cs

示例8: Main

 static void Main(string[] args)
 {
     InitComplements();
       var seq = new List<byte[]>();
       var b = new Block { Count = -1 };
       Index line = Index.None, start = Index.None, end = Index.None;
       using (var r = new BinaryReader(Console.OpenStandardInput())) {
      using (var w = Console.OpenStandardOutput()) {
         while (b.Read(r) > 0) {
            seq.Add(b.Data);
            if (line.Pos < 0) line = b.IndexOf(Gt, 0);
            while (line.Pos >= 0) {
               if (start.Pos < 0) {
                  var off = line.InBlock(b) ? line.Pos : 0;
                  start = b.IndexOf(Lf, off);
                  if (start.Pos < 0) {
                      w.Write(b.Data, off, b.Data.Length - off);
                      seq.Clear(); break;
                  }
                  w.Write(b.Data, off, start.Pos + 1 - off);
               }
               if (end.Pos < 0) {
                  end = b.IndexOf(Gt, start.InBlock(b) ? start.Pos : 0);
                  if (end.Pos < 0) break;
               }
               w.Reverse(start.Pos, end.Pos, seq);
               if (seq.Count > 1) seq.RemoveRange(0, seq.Count - 1);
               line = end; end = Index.None; start = Index.None;
            }
         }
         if (start.Pos >= 0 && end.Pos < 0)
            w.Reverse(start.Pos, seq[seq.Count -1].Length, seq);
      }
       }
 }
开发者ID:kjk,项目名称:kjkpub,代码行数:35,代码来源:revcomp.cs

示例9: Load

    // 바이너리 로드
    public void Load(TextAsset kTa_)
    {
        //FileStream fs = new FileStream("Assets\\Resources\\StageDB.bytes", FileMode.Open);
        //BinaryReader br = new BinaryReader(fs);
        Stream kStream = new MemoryStream (kTa_.bytes);
        BinaryReader br = new BinaryReader(kStream);

        // *주의
        // 바이너리 세이브 순서와 로드 순서가 같아야된다. [5/13/2012 JK]
        // 바이너리 리드
        int iCount = br.ReadInt32();        // 갯수 읽기
        for (int i = 0; i < iCount; ++i)
        {
            StStateInfo kInfo = new StStateInfo();

            kInfo.m_nStageIndex = br.ReadInt32();          // 캐릭터 코드
            // 스테이지 별로 나오는 캐릭터
            kInfo.m_anCharCode = new int[(int)EStageDetail.Count];
            for (int k = 0; k < (int)EStageDetail.Count; ++k)
            {
                kInfo.m_anCharCode[k] = br.ReadInt32();
            }
            kInfo.m_fTermTime = br.ReadSingle();

            m_tmStage.Add(kInfo.m_nStageIndex, kInfo);
        }

        //fs.Close();
        br.Close();
        kStream.Close();
    }
开发者ID:ditto21c,项目名称:ExampleSource,代码行数:32,代码来源:StageDB.cs

示例10: AnimatedMeshCallback

	void AnimatedMeshCallback(string classname, BinaryReader br)
	{
		switch ( classname )
		{
			case "AnimMesh": LoadAnimMesh(br); break;
		}
	}
开发者ID:xiaopangoo,项目名称:MotionPlatform,代码行数:7,代码来源:MegaVertexAnimEditor.cs

示例11: makeBuilding

    public void makeBuilding(float interval,float tmpWidth,int regionWidth,float tmpDepth,float tmpHeight,float[] height)
    {
        int afterX,afterY,galo,selo,building_height;
        FileStream building_fs = new FileStream ("building_data_bin", FileMode.Open);
        BinaryReader reader = new BinaryReader (building_fs);

        int ncols_building = reader.ReadInt32();
        int nrows_building = reader.ReadInt32();

        //Debug.Log ("ncols_building :" + ncols_building);
        //Debug.Log ("nrows_building : " + nrows_building);

        while (reader.PeekChar () != -1) {

            afterX = reader.ReadInt32 ()/(int)interval;		//To adjust the resolution, divid with interval
            afterY = reader.ReadInt32 ()/(int)interval;
            galo = reader.ReadInt32 ();
            selo = reader.ReadInt32 ();

            building_height = reader.ReadInt32();

            /*Debug.Log ("afterX : " + afterX);
            Debug.Log ("afterY : " + afterY);
            Debug.Log ("galo : " + galo);
            Debug.Log ("selo : " + selo);
            Debug.Log ("height : " + building_height);*/

            GameObject building = GameObject.CreatePrimitive(PrimitiveType.Cube);
            building.transform.localScale = new Vector3(galo,selo,building_height);
            building.transform.position = new Vector3(afterX*interval - tmpWidth,((height [regionWidth * afterY + afterX] - tmpDepth)*5f)+(building.transform.localScale.y/2),(afterY* interval - tmpHeight));
            //building.AddComponent<BoxCollider>();
            //building.AddComponent<Rigidbody>().useGravity=false;
            building.AddComponent<clicked_building>();
        }
    }
开发者ID:Hyunsik-Yoo,项目名称:Flood-Simulation,代码行数:35,代码来源:ForTest.cs

示例12: LoadGameSave

    public static GameDataContainer LoadGameSave()
    {
        GameDataContainer data = new GameDataContainer ();

        // Ensure that the file exists, else returns
        if (!File.Exists ("Data/SaveGame.dat"))
            return data;

        using (BinaryReader br = new BinaryReader(File.OpenRead("Data/SaveGame.dat")))
        {
            br.ReadBytes(10); // Header

            int moneyBytes = br.ReadInt32(); // sizeof (money)
            data.Money = new BigInteger(Encoding.ASCII.GetString(br.ReadBytes(moneyBytes))); // money

            // Loop for product data
            for (int i = 0; i < (int)Products.Max; i++)
            {
                int level;
                level = br.ReadInt32();

                data.ProdList[i] = level;
            }

            int upgradeCount = br.ReadInt32();
            for (int i = 0; i < upgradeCount; i++) {
                int upId = br.ReadInt32();
                data.AcquiredUpgrades.Add(upId);
            }
        }

        return data;
    }
开发者ID:guilherme-gm,项目名称:numbers-game,代码行数:33,代码来源:GameLoader.cs

示例13: BtnPutin_Click

    //上传用户导入XML
    protected void BtnPutin_Click(object sender, EventArgs e)
    {
        errMsg = "";
        int count = 0;
        string info = "";
        string flPath = FileUpload1.PostedFile.FileName.ToString();
        string treeID = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName);
        FileStream fs = new FileStream(flPath, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
        BinaryReader br = new BinaryReader(fs);

        byte[] imgBytesIn = br.ReadBytes((int)fs.Length);  //将流读入到字节数组中

        bool flag = bl.RetBoolUpFile(treeID, this.treeName.Value, imgBytesIn, out errMsg);

        if (errMsg == "")
        {
            if (flag == true)
            {
                info = "菜单文件导入成功!";
                count = 1;
            }
            else
            {
                info = "菜单文件导入失败!";
            }
        }
        else
            info = errMsg;
        Response.Redirect(webpath);
    }
开发者ID:eseawind,项目名称:YCJN,代码行数:31,代码来源:ManageTreeMenu.aspx.cs

示例14: LoadBezVector3KeyControl

	static public MegaBezVector3KeyControl LoadBezVector3KeyControl(BinaryReader br)
	{
		con = new MegaBezVector3KeyControl();

		MegaParse.Parse(br, Parse);
		return con;
	}
开发者ID:Gounemond,项目名称:BretarisDemo,代码行数:7,代码来源:MegaParseEditor.cs

示例15: LoadFile

    //Generalized file loading function (basically a copy paste of the titan portion of the code)
    //Loads the file "bodyNameEphem_saturn.dat"
    public Boolean LoadFile(string bodyName, List<DateTime> times)
    {
        string filename = "Assets/Data/"+bodyName+"Ephem_saturn.dat";
        if(File.Exists(filename)) {
            List<Vector3> posList = new List<Vector3>();
            Debug.Log("Loading Titan ephemera");
            BinaryReader binReader = new BinaryReader(File.Open(filename, FileMode.Open));
            bool finished = false;

            while(! finished) {
                try{
                    double x = binReader.ReadDouble();
                    double z = binReader.ReadDouble();
                    double y = binReader.ReadDouble();
                    posList.Add(new Vector3((float) x, (float)y, (float)z));
                } catch (Exception e) {
                    finished = true;
                }
            }

            //Match up the positions and times
            SortedList<DateTime, EphemerisData> titanData = new SortedList<DateTime, EphemerisData>();
            for(int i = 0; i < posList.Count && i < times.Count; i++) {
                titanData.Add(times[i], new EphemerisData(posList[i], times[i]));
            }

            bodies[bodyName] = titanData;
            return true;
        } else return false;
    }
开发者ID:mcclaskc,项目名称:Cassini-Spacecraft-Viewer,代码行数:32,代码来源:FileLoader.cs


注:本文中的BinaryReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。