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


C# UnmanagedMemoryStream.CopyTo方法代码示例

本文整理汇总了C#中System.IO.UnmanagedMemoryStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedMemoryStream.CopyTo方法的具体用法?C# UnmanagedMemoryStream.CopyTo怎么用?C# UnmanagedMemoryStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.UnmanagedMemoryStream的用法示例。


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

示例1: OnFillBuffer

        public unsafe static void OnFillBuffer(byte * pData, long lDataLen)
        {
            Trace.WriteLine(++i + ": _EncodeInternal: " + lDataLen);

            using (var f = File.Open("dump.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                f.Seek(0, SeekOrigin.End);

                using (var b = new BinaryWriter(f))
                {
                    b.Write((int)lDataLen);

                    using (UnmanagedMemoryStream ms = new UnmanagedMemoryStream(pData, lDataLen))
                    {
                        ms.CopyTo(f);
                    }
                }
            }

            //if (m_Bitmap == null)
            //{
            //    m_Bitmap = new Bitmap(@"D:\Dev\comDemo\Filters\logo.bmp");

            //    Rectangle bounds = new Rectangle(0, 0, m_Bitmap.Width, m_Bitmap.Height);
            //    var m_BitmapData = m_Bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            //    var RowSizeBytes = m_BitmapData.Stride;

            //    int total_size = m_BitmapData.Stride * m_BitmapData.Height;
            //    if (ImageBytes == null || ImageBytes.Length != total_size)
            //    {
            //        ImageBytes = new byte[total_size];
            //    }
            //    // Copy the data into the ImageBytes array.
            //    Marshal.Copy(m_BitmapData.Scan0, ImageBytes, 0, total_size);

            //    encoder.EncodeRGBtoI420(ImageBytes, m_Bitmap.Width, m_Bitmap.Height, ref yuv, true);
            //}
            //else
            //if(f != null)
            {
                //f.OnFillBuffer(pData, lDataLen);
            }
        }
开发者ID:chinshou,项目名称:WebRtc.NET,代码行数:43,代码来源:Util.cs

示例2: Update

 public void Update()
 {
     //bool mutexCreated;
     //Mutex mutex = new Mutex(true, "InteractiveSpaceRectifiedTabletopMutex2", out mutexCreated);
     
     using (MemoryMappedViewStream mmfStream = rectifiedTabletopMmf.CreateViewStream())
     {
         unsafe
         {
             ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockFactoryImage(ImageProductType.RectifiedTabletopProduct);
             using (UnmanagedMemoryStream srcStream = new UnmanagedMemoryStream(ptr.BytePtr, imgSize, imgSize, FileAccess.Read))
             {
                 srcStream.CopyTo(mmfStream);
             }
             ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr);
         }
     }
     //mutex.ReleaseMutex();
 }
开发者ID:zhuangfangwang,项目名称:ise,代码行数:19,代码来源:SharedMemoryExporter.cs

示例3: SendTo

        /// <summary>
        /// Sends the specified UIImage to the AirPlay device.
        /// </summary>
        /// <param name='service'>
        /// NSNetService (extension method target) representing the AirPlay device.
        /// </param>
        /// <param name='image'>
        /// The UIImage to be send to the device.
        /// </param>
        /// <param name='complete'>
        /// Optional method to be called when the operation is complete. True will be supplied if the action was
        /// successful, false if a problem occured.
        /// </param>
        public static unsafe void SendTo(this NSNetService service, UIImage image, Action<bool> complete)
        {
            if (service == null) {
                if (complete != null)
                    complete (false);
                return;
            }

            // In general I prefer WebClient *Async methods but it does not provide methods to
            // upload Stream and allocating a (not really required) byte[] is a huge waste
            ThreadPool.QueueUserWorkItem (delegate {
                bool ok = true;
                try {
                    string url = String.Format ("http://{0}:{1}/photo", service.HostName, service.Port);
                    var req = (HttpWebRequest) WebRequest.Create (url);
                    using (var data = image.AsJPEG ()) {
                        req.Method = "PUT";
                        req.ContentLength = (int) data.Length;
                        req.UserAgent = "AirPlay/160.4 (Photos)";
                        req.Headers.Add ("X-Apple-AssetKey", Guid.NewGuid ().ToString ());
                        req.Headers.Add ("X-Apple-Session-ID", session.ToString ());
                        var s = req.GetRequestStream ();
                        using (Stream ums = new UnmanagedMemoryStream ((byte *) data.Bytes, (int) data.Length))
                            ums.CopyTo (s);
                    }
                    req.GetResponse ().Dispose ();
                }
                catch {
                    ok = false;
                }
                finally {
                    if (complete != null) {
                        NSRunLoop.Main.InvokeOnMainThread (delegate {
                            complete (ok);
                        });
                    }
                }
            });
        }
开发者ID:spouliot,项目名称:airplay,代码行数:52,代码来源:AirPlayRocks.cs

示例4: CreateSound

 public Sound CreateSound(UnmanagedMemoryStream data, SoundMode mode = SoundMode.Default)
 {
     var stream = new MemoryStream();
     data.CopyTo(stream);
     return CreateSound(stream.ToArray(), mode);
 }
开发者ID:nathanchere,项目名称:nFMOD,代码行数:6,代码来源:FmodSystem.cs

示例5: Compile

        public unsafe void Compile(ScriptSource source, Stream compiledCodeDestination)
        {
            ClaimContext();

            uint bufferSize = 0;
            Errors.ThrowIfIs(api_.JsSerializeScript(source.SourceText, IntPtr.Zero, ref bufferSize));
            if (bufferSize > int.MaxValue)
                throw new OutOfMemoryException();

            IntPtr mem = Marshal.AllocCoTaskMem(unchecked((int)bufferSize));
            var error = api_.JsSerializeScript(source.SourceText, mem, ref bufferSize);
            if (error != JsErrorCode.JsNoError)
            {
                Marshal.FreeCoTaskMem(mem);
                Errors.ThrowFor(error);
            }

            using (UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)mem.ToPointer(), bufferSize))
            {
                ums.CopyTo(compiledCodeDestination);
            }
            Marshal.FreeCoTaskMem(mem);
        }
开发者ID:Lercher,项目名称:jsrt-dotnet,代码行数:23,代码来源:JavaScriptEngine.cs

示例6: SaveTerrain

        public unsafe void SaveTerrain(string path, string name)
        {
            using (var stream = File.Create(path))
            {
                using (var bw = new BinaryWriter(stream, Encoding.Default, true))
                {
                    bw.Write(name);

                    bw.Write(this.Size.Width);
                    bw.Write(this.Size.Height);
                    bw.Write(this.Size.Depth);
                }

                fixed (TileData* v = this.m_tileGrid)
                {
                    byte* p = (byte*)v;
                    using (var memStream = new UnmanagedMemoryStream(p, this.Size.Volume * sizeof(TileData)))
                        memStream.CopyTo(stream);
                }

                fixed (byte* v = this.m_levelMap)
                {
                    byte* p = (byte*)v;
                    using (var memStream = new UnmanagedMemoryStream(p, this.Width * this.Height * sizeof(byte)))
                        memStream.CopyTo(stream);
                }
            }
        }
开发者ID:tomba,项目名称:dwarrowdelf,代码行数:28,代码来源:TerrainData.cs

示例7: WriteMesh

		unsafe void WriteMesh (Mesh mesh, BinaryWriter writer) {
			var boneSlotCount = this.GetBoneSlotCount(mesh);

			VertexFlags flags;
			int stride;
			this.GetVertexFormat(mesh, boneSlotCount, out flags, out stride);
			var count = mesh.VertexCount;

			writer.Write(mesh.Name);
			writer.Write((uint)flags);
			writer.Write(boneSlotCount);
			writer.Write(mesh.MaterialIndex);
			var vertices = new float[stride * count];
			int idx = 0, offset = 0;
			foreach (var pos in mesh.Vertices) {
				vertices[idx] = pos.X;
				vertices[idx + 1] = pos.Y;
				vertices[idx + 2] = pos.Z;
				idx += stride;
			}
			offset = idx = 3;
			if (mesh.HasNormals) {
				foreach (var norm in mesh.Normals) {
					vertices[idx] = norm.X;
					vertices[idx + 1] = norm.Y;
					vertices[idx + 2] = norm.Z;
					idx += stride;
				}
				offset += 3;
				idx = offset;
			}
			for (var i = 0; i < 4; i++) {
				if (mesh.HasTextureCoords(i)) {
					if (mesh.UVComponentCount[i] != 2)
						Console.WriteLine("WARNING: texture coordinates should have 2 components, but this channel has " + mesh.UVComponentCount[i]);
					foreach (var uv in mesh.TextureCoordinateChannels[i]) {
						vertices[idx] = uv.X;
						vertices[idx + 1] = uv.Y;
						idx += stride;
					}
					offset += 2;
					idx = offset;
				}
			}
			for (var i = 0; i < 4; i++) {
				if (mesh.HasVertexColors(i)) {
					foreach (var c in mesh.VertexColorChannels[i]) {
						vertices[idx] = c.R;
						vertices[idx + 1] = c.G;
						vertices[idx + 2] = c.B;
						vertices[idx + 3] = c.A;
						idx += stride;
					}
					offset += 4;
					idx = offset;
				}
			}
			// add bone information to every vertex
			for(var i = 0; i < mesh.BoneCount; i++) {
				foreach (var weight in mesh.Bones[i].VertexWeights) {
					if (weight.Weight > 0f) {
						idx = (stride * weight.VertexID) + offset;
						while (vertices[idx] != 0f)
							idx++;
						vertices[idx] = weight.Weight;
						vertices[idx + boneSlotCount] = i;
					}
				}
			}
			writer.Write(vertices.Length);
			writer.Flush();
			fixed(float *fp = &vertices[0]) {
				byte* bp = (byte*)fp;
				using (var ms = new UnmanagedMemoryStream(bp, vertices.Length * sizeof(float))) {
					ms.CopyTo(writer.BaseStream);
				}
			}

			count = mesh.FaceCount;
			var indices = new int[count * 3];
			idx = 0;
			for (var i = 0; i < count; i++) {
				var face = mesh.Faces[i];
				var faceIndices = face.Indices;
				if (face.IndexCount != 3)
					throw new InvalidOperationException("Polygonal faces are not supported, faces must be triangles.");
				indices[idx++] = faceIndices[0];
				indices[idx++] = faceIndices[1];
				indices[idx++] = faceIndices[2];
			}
			writer.Write(indices.Length);
			writer.Flush();
			fixed(int *ip = &indices[0]) {
				byte* bp = (byte*)ip;
				using (var ms = new UnmanagedMemoryStream(bp, indices.Length * sizeof(float))) {
					ms.CopyTo(writer.BaseStream);
				}
			}

			count = mesh.BoneCount;
//.........这里部分代码省略.........
开发者ID:jpernst,项目名称:GameStack,代码行数:101,代码来源:ModelImporter.cs


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