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


C# DataStream.WriteByte方法代码示例

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


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

示例1: Main

        /// <summary>
        /// SharpDX WIC sample. Encode to JPG and decode.
        /// </summary>
        static void Main()
        {
            const int width = 512;
            const int height = 512;
            const string filename = "output.jpg";

            var factory = new ImagingFactory();

            WICStream stream = null;

            // ------------------------------------------------------
            // Encode a JPG image
            // ------------------------------------------------------

            // Create a WIC outputstream 
            if (File.Exists(filename))
                File.Delete(filename);

            stream = new WICStream(factory, filename, NativeFileAccess.Write);

            // Initialize a Jpeg encoder with this stream
            var encoder = new JpegBitmapEncoder(factory);
            encoder.Initialize(stream);

            // Create a Frame encoder
            var bitmapFrameEncode = new BitmapFrameEncode(encoder);
            bitmapFrameEncode.Options.ImageQuality = 0.8f;
            bitmapFrameEncode.Initialize();
            bitmapFrameEncode.SetSize(width, height);
            var guid = PixelFormat.Format24bppBGR;
            bitmapFrameEncode.SetPixelFormat(ref guid);

            // Write a pseudo-plasma to a buffer
            int stride = PixelFormat.GetStride(PixelFormat.Format24bppBGR, width);
            var bufferSize = height * stride;
            var buffer = new DataStream(bufferSize, true, true);
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    buffer.WriteByte((byte)(x / 2.0 + 20.0 * Math.Sin(y / 40.0)));
                    buffer.WriteByte((byte)(y / 2.0 + 30.0 * Math.Sin(x / 80.0)));
                    buffer.WriteByte((byte)(x / 2.0));
                }
            }

            // Copy the pixels from the buffer to the Wic Bitmap Frame encoder
            bitmapFrameEncode.WritePixels(512, new DataRectangle(buffer.DataPointer, stride));

            // Commit changes
            bitmapFrameEncode.Commit();
            encoder.Commit();
            bitmapFrameEncode.Dispose();
            encoder.Dispose();
            stream.Dispose();

            // ------------------------------------------------------
            // Decode the previous JPG image
            // ------------------------------------------------------

            // Read input
            stream = new WICStream(factory, filename, NativeFileAccess.Read);
            var decoder = new JpegBitmapDecoder(factory);
            decoder.Initialize(stream, DecodeOptions.CacheOnDemand);
            var bitmapFrameDecode = decoder.GetFrame(0);
            var queryReader = bitmapFrameDecode.MetadataQueryReader;

            // Dump MetadataQueryreader
            queryReader.Dump(Console.Out);
            queryReader.Dispose();

            bitmapFrameDecode.Dispose();
            decoder.Dispose();
            stream.Dispose();

            // Dispose
            factory.Dispose();

            System.Diagnostics.Process.Start(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, filename)));
        }
开发者ID:MaybeMars,项目名称:SharpDX-Samples,代码行数:83,代码来源:Program.cs

示例2: TextureFromColor

        public static SlimDX.Direct3D11.Texture2D TextureFromColor(SlimDX.Direct3D11.Device device, Color4 color, out SlimDX.Direct3D11.ShaderResourceView srv)
        {
            /*SlimDX.Direct3D11.Texture2DDescription desc2 = new SlimDX.Direct3D11.Texture2DDescription();
            desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
            desc2.Width = 1;
            desc2.Height = 1;
            desc2.MipLevels = 1;
            desc2.ArraySize = 1;
            desc2.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
            desc2.Usage = SlimDX.Direct3D11.ResourceUsage.Dynamic;
            desc2.BindFlags = SlimDX.Direct3D11.BindFlags.ShaderResource;
            desc2.CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.Write;
            SlimDX.Direct3D11.Texture2D texture = new SlimDX.Direct3D11.Texture2D(device, desc2);

            // fill the texture with rgba values
            DataRectangle rect = texture.AsSurface().Map(SlimDX.DXGI.MapFlags.Write | SlimDX.DXGI.MapFlags.Discard);
            if (rect.Data.CanWrite)
            {
                for (int row = 0; row < texture.Description.Height; row++)
                {
                    int rowStart = row * rect.Pitch;
                    rect.Data.Seek(rowStart, System.IO.SeekOrigin.Begin);
                    for (int col = 0; col < texture.Description.Width; col++)
                    {
                        rect.Data.WriteByte((byte)(color.Red * 255));
                        rect.Data.WriteByte((byte)(color.Green * 255));
                        rect.Data.WriteByte((byte)(color.Blue * 255));
                        rect.Data.WriteByte((byte)(color.Alpha * 255));
                    }
                }
            }
            texture.AsSurface().Unmap();
            texture.AsSurface().Dispose();

            srv = GetShaderResourceView(device, texture);*/

            SlimDX.Direct3D11.Texture2DDescription desc2 = new SlimDX.Direct3D11.Texture2DDescription();
            desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
            desc2.Width = 1;
            desc2.Height = 1;
            desc2.MipLevels = 1;
            desc2.ArraySize = 1;
            desc2.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
            desc2.Usage = SlimDX.Direct3D11.ResourceUsage.Default;
            desc2.BindFlags = SlimDX.Direct3D11.BindFlags.ShaderResource;
            desc2.CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None;

            // fill the texture with rgba values
            DataStream stream = new DataStream(sizeof(byte) * 4, false, true);
            stream.WriteByte((byte)(color.Red * 255));
            stream.WriteByte((byte)(color.Green * 255));
            stream.WriteByte((byte)(color.Blue * 255));
            stream.WriteByte((byte)(color.Alpha * 255));
            stream.Position = 0;

            SlimDX.Direct3D11.Texture2D texture = new SlimDX.Direct3D11.Texture2D(device, desc2, new DataRectangle(1, stream));
            srv = GetShaderResourceView(device, texture);
            return texture;
        }
开发者ID:RomanHodulak,项目名称:DeferredLightingD3D11,代码行数:59,代码来源:ContentHelper.cs


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