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


C# ImageDescription类代码示例

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


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

示例1: LoadFromMemory

        public static unsafe Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
        {
            var stream = new BinarySerializationReader(new NativeMemoryStream((byte*)pSource, size));

            // Read and check magic code
            var magicCode = stream.ReadUInt32();
            if (magicCode != MagicCode)
                return null;

            // Read header
            var imageDescription = new ImageDescription();
            imageDescriptionSerializer.Serialize(ref imageDescription, ArchiveMode.Deserialize, stream);

            if (makeACopy)
            {
                var buffer = Utilities.AllocateMemory(size);
                Utilities.CopyMemory(buffer, pSource, size);
                pSource = buffer;
                makeACopy = false;
            }

            var image = new Image(imageDescription, pSource, 0, handle, !makeACopy);

            var totalSizeInBytes = stream.ReadInt32();
            if (totalSizeInBytes != image.TotalSizeInBytes)
                throw new InvalidOperationException("Image size is different than expected.");

            // Read image data
            stream.Serialize(image.DataPointer, image.TotalSizeInBytes);

            return image;
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:32,代码来源:ImageHelper.cs

示例2: SaveFromMemory

        private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, ImageFormat imageFormat)
        {
            using (var bitmap = new Bitmap(description.Width, description.Height))
            {
                var sourceArea = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                try
                {
                    // Copy memory
                    if (description.Format == PixelFormat.R8G8B8A8_UNorm || description.Format == PixelFormat.R8G8B8A8_UNorm_SRgb)
                        CopyMemoryBGRA(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
                    else if (description.Format == PixelFormat.B8G8R8A8_UNorm || description.Format == PixelFormat.B8G8R8A8_UNorm_SRgb)
                        Utilities.CopyMemory(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
                    else
                        throw new NotSupportedException(string.Format("Pixel format [{0}] is not supported", description.Format));
                }
                finally
                {
                    bitmap.UnlockBits(bitmapData);
                }

                // Save
                bitmap.Save(imageStream, imageFormat);
            }
        }
开发者ID:joewan,项目名称:xenko,代码行数:28,代码来源:StandardImageHelper.Windows.cs

示例3: SaveFromMemory

        private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, Bitmap.CompressFormat imageFormat)
        {
            var colors = pixelBuffers[0].GetPixels<int>();

            using (var bitmap = Bitmap.CreateBitmap(description.Width, description.Height, Bitmap.Config.Argb8888))
            {
                var pixelData = bitmap.LockPixels();
                var sizeToCopy = colors.Length * sizeof(int);

                unsafe
                {
                    fixed (int* pSrc = colors)
                    {
                        // Copy the memory
                        if (description.Format == PixelFormat.R8G8B8A8_UNorm || description.Format == PixelFormat.R8G8B8A8_UNorm_SRgb)
                        {
                            CopyMemoryBGRA(pixelData, (IntPtr)pSrc, sizeToCopy);
                        }
                        else if (description.Format == PixelFormat.B8G8R8A8_UNorm || description.Format == PixelFormat.B8G8R8A8_UNorm_SRgb)
                        {
                            Utilities.CopyMemory(pixelData, (IntPtr)pSrc, sizeToCopy);
                        }
                        else
                        {
                            throw new NotSupportedException(string.Format("Pixel format [{0}] is not supported", description.Format));
                        }
                    }
                }

                bitmap.UnlockPixels();
                bitmap.Compress(imageFormat, 100, imageStream);
            }
        }
开发者ID:cg123,项目名称:xenko,代码行数:33,代码来源:StandardImageHelper.Android.cs

示例4: Read

        public void Read(BinaryReader reader)
        {
            TestName = reader.ReadString();
            CurrentVersion = reader.ReadString();
            Frame = reader.ReadString();

            // Read image header
            var width = reader.ReadInt32();
            var height = reader.ReadInt32();
            var format = (PixelFormat)reader.ReadInt32();
            var textureSize = reader.ReadInt32();

            // Read image data
            var imageData = new byte[textureSize];
            using (var lz4Stream = new LZ4Stream(reader.BaseStream, CompressionMode.Decompress, false, textureSize))
            {
                if (lz4Stream.Read(imageData, 0, textureSize) != textureSize)
                    throw new EndOfStreamException("Unexpected end of stream");
            }

            var pinnedImageData = GCHandle.Alloc(imageData, GCHandleType.Pinned);
            var description = new ImageDescription
            {
                Dimension = TextureDimension.Texture2D,
                Width = width,
                Height = height,
                ArraySize = 1,
                Depth = 1,
                Format = format,
                MipLevels = 1,
            };

            Image = Image.New(description, pinnedImageData.AddrOfPinnedObject(), 0, pinnedImageData, false);
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:34,代码来源:TestResultImage.cs

示例5: SaveFromMemory

 private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, Bitmap.CompressFormat imageFormat)
 {
     var colors = pixelBuffers[0].GetPixels<int>();
     using (var bitmap = Bitmap.CreateBitmap(colors, description.Width, description.Height, Bitmap.Config.Argb8888))
     {
         bitmap.Compress(imageFormat, 0, imageStream);
     }
 }
开发者ID:Powerino73,项目名称:paradox,代码行数:8,代码来源:StandardImageHelper.Android.cs

示例6: SaveFromMemory

        public static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, System.IO.Stream imageStream)
        {
            var stream = new BinarySerializationWriter(imageStream);

            // Write magic code
            stream.Write(MagicCode);

            // Write image header
            imageDescriptionSerializer.Serialize(ref description, ArchiveMode.Serialize, stream);

            // Write total size
            int totalSize = 0;
            foreach (var pixelBuffer in pixelBuffers)
                totalSize += pixelBuffer.BufferStride;

            stream.Write(totalSize);

            // Write buffers contiguously
            foreach (var pixelBuffer in pixelBuffers)
            {
                stream.Serialize(pixelBuffer.DataPointer, pixelBuffer.BufferStride);
            }
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:23,代码来源:ImageHelper.cs

示例7: CreateTextureFromDDS

        // Simple DDS loader ported from http://msdn.microsoft.com/en-us/library/windows/apps/jj651550.aspx
        static void CreateTextureFromDDS(
            SharpDX.Direct3D11.Device d3dDevice,
            ImageDescription imageDesc,
            //SharpDX.Toolkit.Graphics.DDS.Header header,
            //DDS_HEADER* header,
            IntPtr bitData,
            //_In_reads_bytes_(bitSize) const byte* bitData,
            int bitSize,
            out SharpDX.Direct3D11.Resource texture,
            //_Out_opt_ ID3D11Resource** texture,
            out ShaderResourceView textureView
            //_Out_opt_ ID3D11ShaderResourceView** textureView,
            )
        {
            int width = imageDesc.Width;
            int height = imageDesc.Height;
            int depth = imageDesc.Depth;

            int arraySize = imageDesc.ArraySize;
            Format format = imageDesc.Format;
            bool isCubeMap = imageDesc.Dimension == TextureDimension.TextureCube;

            int mipCount = imageDesc.MipLevels;// MipMapCount;
            if (0 == mipCount)
            {
                mipCount = 1;
            }

            // Create the texture
            DataBox[] initData = new DataBox[mipCount * arraySize];
            //std::unique_ptr<D3D11_SUBRESOURCE_DATA> initData(new D3D11_SUBRESOURCE_DATA[mipCount * arraySize]);

            int maxsize = 1;
            if (isCubeMap)
            {
                maxsize = SharpDX.Direct3D11.Resource.MaximumTextureCubeSize;
            }
            else
            {
                maxsize = (imageDesc.Dimension == TextureDimension.Texture3D)
                    ? SharpDX.Direct3D11.Resource.MaximumTexture3DSize
                    : SharpDX.Direct3D11.Resource.MaximumTexture2DSize;
            }

            int skipMip = 0;
            int twidth = 0;
            int theight = 0;
            int tdepth = 0;
            FillInitData(width, height, depth, mipCount, arraySize, format, maxsize, bitSize, bitData, out twidth, out theight, out tdepth, out skipMip, initData);

            CreateD3DResources(d3dDevice, imageDesc.Dimension, twidth, theight, tdepth, mipCount - skipMip, arraySize, format, isCubeMap, initData, out texture, out textureView);
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:53,代码来源:DDSHelper.cs

示例8: CalculateMipMapDescription

        internal static MipMapDescription[] CalculateMipMapDescription(ImageDescription metadata, PitchFlags cpFlags, out int nImages, out int pixelSize)
        {
            pixelSize = 0;
            nImages = 0;

            int w = metadata.Width;
            int h = metadata.Height;
            int d = metadata.Depth;

            var mipmaps = new MipMapDescription[metadata.MipLevels];

            for (int level = 0; level < metadata.MipLevels; ++level)
            {
                int rowPitch, slicePitch;
                int widthPacked;
                int heightPacked;
                ComputePitch(metadata.Format, w, h, out rowPitch, out slicePitch, out widthPacked, out heightPacked, PitchFlags.None);

                mipmaps[level] = new MipMapDescription(
                    w,
                    h,
                    d,
                    rowPitch,
                    slicePitch,
                    widthPacked,
                    heightPacked
                    );

                pixelSize += d * slicePitch;
                nImages += d;

                if (h > 1)
                    h >>= 1;

                if (w > 1)
                    w >>= 1;

                if (d > 1)
                    d >>= 1;
            }
            return mipmaps;
        }
开发者ID:Julyuary,项目名称:paradox,代码行数:42,代码来源:Image.cs

示例9: Save

        /// <summary>
        /// Saves this instance to a stream.
        /// </summary>
        /// <param name="pixelBuffers">The buffers to save.</param>
        /// <param name="count">The number of buffers to save.</param>
        /// <param name="description">Global description of the buffer.</param>
        /// <param name="imageStream">The destination stream.</param>
        /// <param name="fileType">Specify the output format.</param>
        /// <remarks>This method support the following format: <c>dds, bmp, jpg, png, gif, tiff, wmp, tga</c>.</remarks>
        internal static void Save(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, ImageFileType fileType)
        {
            foreach (var loadSaveDelegate in loadSaveDelegates)
            {
                if (loadSaveDelegate.FileType == fileType)
                {
                    loadSaveDelegate.Save(pixelBuffers, count, description, imageStream);
                    return;
                }

            }
            throw new NotSupportedException("This file format is not yet implemented.");
        }
开发者ID:Julyuary,项目名称:paradox,代码行数:22,代码来源:Image.cs

示例10: New

 /// <summary>
 /// Creates a new instance of <see cref="Image"/> from an image description.
 /// </summary>
 /// <param name="description">The image description.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 public static Image New(ImageDescription description, IntPtr dataPointer)
 {
     return new Image(description, dataPointer, 0, null, false);
 }
开发者ID:Julyuary,项目名称:paradox,代码行数:10,代码来源:Image.cs

示例11: Image

 /// <summary>
 /// Initializes a new instance of the <see cref="Image" /> class.
 /// </summary>
 /// <param name="description">The image description.</param>
 /// <param name="dataPointer">The pointer to the data buffer.</param>
 /// <param name="offset">The offset from the beginning of the data buffer.</param>
 /// <param name="handle">The handle (optionnal).</param>
 /// <param name="bufferIsDisposable">if set to <c>true</c> [buffer is disposable].</param>
 /// <exception cref="System.InvalidOperationException">If the format is invalid, or width/height/depth/arraysize is invalid with respect to the dimension.</exception>
 internal unsafe Image(ImageDescription description, IntPtr dataPointer, int offset, GCHandle? handle, bool bufferIsDisposable, PitchFlags pitchFlags = PitchFlags.None, int rowStride = 0)
 {
     Initialize(description, dataPointer, offset, handle, bufferIsDisposable, pitchFlags, rowStride);
 }
开发者ID:Julyuary,项目名称:paradox,代码行数:13,代码来源:Image.cs

示例12: DecodeMetadata

        /// <summary>
        /// Determines metadata for image
        /// </summary>
        /// <param name="flags">The flags.</param>
        /// <param name="decoder">The decoder.</param>
        /// <param name="frame">The frame.</param>
        /// <param name="pixelFormat">The pixel format.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">If pixel format is not supported.</exception>
        private static ImageDescription? DecodeMetadata(WICFlags flags, BitmapDecoder decoder, BitmapFrameDecode frame, out Guid pixelFormat)
        {
            var size = frame.Size;

            var metadata = new ImageDescription
                               {
                                   Dimension = TextureDimension.Texture2D,
                                   Width = size.Width,
                                   Height = size.Height,
                                   Depth = 1,
                                   MipLevels = 1,
                                   ArraySize = (flags & WICFlags.AllFrames) != 0 ? decoder.FrameCount : 1,
                                   Format = DetermineFormat(frame.PixelFormat, flags, out pixelFormat)
                               };

            if (metadata.Format == DXGI.Format.Unknown)
                return null;

            return metadata;
        }
开发者ID:numo16,项目名称:SharpDX,代码行数:29,代码来源:WICHelper.cs

示例13: SaveFromMemory

        private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, ImageFormat imageFormat)
        {
#if (SILICONSTUDIO_XENKO_UI_WINFORMS || SILICONSTUDIO_XENKO_UI_WPF)
            using (var bitmap = new Bitmap(description.Width, description.Height))
            {
                var sourceArea = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                try
                {
                    // Copy memory
                    if (description.Format == PixelFormat.R8G8B8A8_UNorm || description.Format == PixelFormat.R8G8B8A8_UNorm_SRgb)
                        CopyMemoryBGRA(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
                    else if (description.Format == PixelFormat.B8G8R8A8_UNorm || description.Format == PixelFormat.B8G8R8A8_UNorm_SRgb)
                        Utilities.CopyMemory(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
                    else
                    {
                        // TODO Ideally we will want to support grayscale images, but the SpriteBatch can only render RGBA for now
                        //  so convert the grayscale image as an RGBA and save it
                        CopyMemoryRRR1(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
                    }
                }
                finally
                {
                    bitmap.UnlockBits(bitmapData);
                }

                // Save
                bitmap.Save(imageStream, imageFormat);
            }
#else
            // FIXME: Manu: Currently SDL can only save to BMP or PNG.
#endif
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:36,代码来源:StandardImageHelper.Windows.cs

示例14: SaveJpgFromMemory

 public static void SaveJpgFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
 {
     SaveFromMemory(pixelBuffers, count, description, imageStream, ImageFormat.Jpeg);
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:4,代码来源:StandardImageHelper.Windows.cs

示例15: CalculateImageArray

        /// <summary>
        /// Determines number of image array entries and pixel size.
        /// </summary>
        /// <param name="imageDesc">Description of the image to create.</param>
        /// <param name="pitchFlags">Pitch flags.</param>
        /// <param name="bufferCount">Output number of mipmap.</param>
        /// <param name="pixelSizeInBytes">Output total size to allocate pixel buffers for all images.</param>
        private static List<int> CalculateImageArray( ImageDescription imageDesc, PitchFlags pitchFlags, out int bufferCount, out int pixelSizeInBytes)
        {
            pixelSizeInBytes = 0;
            bufferCount = 0;

            var mipmapToZIndex = new List<int>();

            for (int j = 0; j < imageDesc.ArraySize; j++)
            {
                int w = imageDesc.Width;
                int h = imageDesc.Height;
                int d = imageDesc.Depth; 
                
                for (int i = 0; i < imageDesc.MipLevels; i++)
                {
                    int rowPitch, slicePitch;
                    int widthPacked;
                    int heightPacked;
                    ComputePitch(imageDesc.Format, w, h, out rowPitch, out slicePitch, out widthPacked, out heightPacked, pitchFlags);

                    // Store the number of z-slicec per miplevels
                    if ( j == 0)
                        mipmapToZIndex.Add(bufferCount);

                    // Keep a trace of indices for the 1st array size, for each mip levels
                    pixelSizeInBytes += d * slicePitch;
                    bufferCount += d;

                    if (h > 1)
                        h >>= 1;

                    if (w > 1)
                        w >>= 1;

                    if (d > 1)
                        d >>= 1;
                }

                // For the last mipmaps, store just the number of zbuffers in total
                if (j == 0)
                    mipmapToZIndex.Add(bufferCount);
            }
            return mipmapToZIndex;
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:51,代码来源:Image.cs


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