當前位置: 首頁>>代碼示例>>C#>>正文


C# TexImage.Clone方法代碼示例

本文整理匯總了C#中SiliconStudio.TextureConverter.TexImage.Clone方法的典型用法代碼示例。如果您正苦於以下問題:C# TexImage.Clone方法的具體用法?C# TexImage.Clone怎麽用?C# TexImage.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SiliconStudio.TextureConverter.TexImage的用法示例。


在下文中一共展示了TexImage.Clone方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Save

        /// <summary>
        /// Saves the specified <see cref="TexImage"/> into a file with the specified format.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="format">The new format.</param>
        /// <param name="minimumMipMapSize">Minimum size of the mip map.</param>
        public void Save(TexImage image, String fileName, PixelFormat format, int minimumMipMapSize = 1)
        {
            if (fileName == null || fileName.Equals(""))
            {
                Log.Error("No file name entered.");
                throw new TextureToolsException("No file name entered.");
            }

            if (minimumMipMapSize < 0)
            {
                Log.Error("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.");
                throw new TextureToolsException("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.");
            }

            if (image.Format != format && format.IsCompressed() && !image.Format.IsCompressed())
            {
                TexImage workingImage = (TexImage)image.Clone();
                Compress(workingImage, format);
                ExecuteRequest(workingImage, new ExportRequest(fileName, minimumMipMapSize));
                workingImage.Dispose();
            }
            else if (image.Format != format && format.IsCompressed())
            {
                TexImage workingImage = (TexImage)image.Clone();
                Decompress(workingImage, image.Format.IsSRgb());
                Compress(workingImage, format);
                ExecuteRequest(workingImage, new ExportRequest(fileName, minimumMipMapSize));
                workingImage.Dispose();
            }
            else
            {
                ExecuteRequest(image, new ExportRequest(fileName, minimumMipMapSize));
            }
        }
開發者ID:Kurooka,項目名稱:paradox,代碼行數:41,代碼來源:TextureTool.cs

示例2: CreateImageFromAlphaComponent

        /// <summary>
        /// Create a new image from the alpha component of a reference image.
        /// </summary>
        /// <param name="texImage">The image from which to take the alpha</param>
        /// <returns>The <see cref="TexImage"/> containing the alpha component as rgb color. Note: it is the user responsibility to dispose the returned image.</returns>
        public unsafe TexImage CreateImageFromAlphaComponent(TexImage texImage)
        {
            if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed())
                throw new NotImplementedException();

            var alphaImage = (TexImage)texImage.Clone(true);

            var rowPtr = alphaImage.Data;
            for (int i = 0; i < alphaImage.Height; i++)
            {
                var pByte = (byte*)rowPtr;
                for (int x = 0; x < alphaImage.Width; x++)
                {
                    pByte[0] = pByte[3];
                    pByte[1] = pByte[3];
                    pByte[2] = pByte[3];

                    pByte += 4;
                }
                rowPtr = IntPtr.Add(rowPtr, alphaImage.RowPitch);
            }

            return alphaImage;
        }
開發者ID:Kurooka,項目名稱:paradox,代碼行數:29,代碼來源:TextureTool.cs

示例3: CreateImageFromAlphaComponent

        /// <summary>
        /// Create a new image from the alpha component of a reference image.
        /// </summary>
        /// <param name="texImage">The image from which to take the alpha</param>
        /// <returns>The <see cref="TexImage"/> containing the alpha component as rgb color. Note: it is the user responsibility to dispose the returned image.</returns>
        public unsafe TexImage CreateImageFromAlphaComponent(TexImage texImage)
        {
            var alphaImage = (TexImage)texImage.Clone(true);

            var rowPtr = alphaImage.Data;
            for (int i = 0; i < alphaImage.Height; i++)
            {
                var pByte = (byte*)rowPtr;
                for (int x = 0; x < alphaImage.Width; x++)
                {
                    pByte[0] = pByte[3];
                    pByte[1] = pByte[3];
                    pByte[2] = pByte[3];

                    pByte += 4;
                }
                rowPtr = IntPtr.Add(rowPtr, alphaImage.RowPitch);
            }

            return alphaImage;
        }
開發者ID:robterrell,項目名稱:paradox,代碼行數:26,代碼來源:TextureTool.cs


注:本文中的SiliconStudio.TextureConverter.TexImage.Clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。