• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TextureFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GenerateToTexture

        /// <summary>
        /// Generates a texture containing the given graph's noise output.
        /// If this is being called very often, create a permanent render target and material and
        ///     use the other version of this method instead for much better performance.
        /// If an error occurred, outputs to the Unity debug console and returns "null".
        /// </summary>
        /// <param name="outputComponents">
        /// The texture output.
        /// For example, pass "rgb" or "xyz" to output the noise into the red, green, and blue channels
        ///     but not the alpha channel.
        /// </param>
        /// <param name="defaultColor">
        /// The color (generally 0-1) of the color components which aren't set by the noise.
        /// </param>
        public static Texture2D GenerateToTexture(Graph g, GraphParamCollection c, int width, int height,
												  string outputComponents, float defaultColor,
												  TextureFormat format = TextureFormat.RGBAFloat)
        {
            //Generate a shader from the graph and have Unity compile it.
            string shaderPath = Path.Combine(Application.dataPath, "gpuNoiseShaderTemp.shader");
            Shader shader = SaveShader(g, shaderPath, "TempGPUNoiseShader", outputComponents, defaultColor);
            if (shader == null)
            {
                return null;
            }

            //Render the shader's output into a render texture and copy the data to a Texture2D.
            RenderTexture target = new RenderTexture(width, height, 16, RenderTextureFormat.ARGBFloat);
            target.Create();
            Texture2D resultTex = new Texture2D(width, height, format, false, true);

            //Create the material and set its parameters.
            Material mat = new Material(shader);
            c.SetParams(mat);

            GraphUtils.GenerateToTexture(target, mat, resultTex);

            //Clean up.
            target.Release();
            if (!AssetDatabase.DeleteAsset(StringUtils.GetRelativePath(shaderPath, "Assets")))
            {
                Debug.LogError("Unable to delete temp file: " + shaderPath);
            }

            return resultTex;
        }
开发者ID:heyx3,项目名称:GPUNoiseForUnity,代码行数:46,代码来源:GraphEditorUtils.cs


示例2: LoadTextureDXT

        public static Texture2D LoadTextureDXT( string path, TextureFormat format, bool mipmap = true )
        {
            var a = Path.Combine( GenFilePaths.CoreModsFolderPath, LoadedModManager.LoadedMods.ToList().Find( s => s.name == "LT_RedistHeat" ).name );
            var b = Path.Combine( a, "Textures" );
            var filePath = Path.Combine( b,  path + ".dds");
            var bytes = File.ReadAllBytes( filePath );

            if (format != TextureFormat.DXT1 && format != TextureFormat.DXT5)
                throw new Exception("Invalid TextureFormat. Only DXT1 and DXT5 formats are supported by this method.");

            var ddsSizeCheck = bytes[4];
            if (ddsSizeCheck != 124)
                throw new Exception("Invalid DDS DXT texture. Unable to read");  //this header byte should be 124 for DDS image files

            var height = bytes[13] * 256 + bytes[12];
            var width = bytes[17] * 256 + bytes[16];

            var dxtBytes = new byte[bytes.Length - DDSHeaderSize];
            Buffer.BlockCopy(bytes, DDSHeaderSize, dxtBytes, 0, bytes.Length - DDSHeaderSize);

            var texture = new Texture2D(width, height, format, mipmap);
            texture.LoadRawTextureData(dxtBytes);
            texture.Apply();

            return (texture);
        }
开发者ID:ForsakenShell,项目名称:RimWorld-RedistHeat,代码行数:26,代码来源:DXTLoader.cs


示例3: CreateClipMask

        public static Texture2D CreateClipMask(float[] heightMap, int size, float shoreLevel, TextureFormat format)
        {
            Texture2D mask = new Texture2D(size, size, format, false, true);
            mask.filterMode = FilterMode.Bilinear;

            int s2 = size * size;

            Color[] colors = new Color[s2];

            for (int i = 0; i < s2; i++)
            {
                float h = Mathf.Clamp(heightMap[i] - shoreLevel, 0.0f, 1.0f);

                if (h > 0.0f) h = 1.0f;

                colors[i].r = h;
                colors[i].g = h;
                colors[i].b = h;
                colors[i].a = h;
            }

            mask.SetPixels(colors);

            mask.Apply();

            return mask;
        }
开发者ID:BenjaminLovegrove,项目名称:ATR,代码行数:27,代码来源:ShoreMaskGenerator.cs


示例4: OpenTexture

        public void OpenTexture(Stream data, string fname, TextureFormat format)
        {
            Bitmap textureBitmap;
            Texture.Read(data, out textureBitmap, format);

            DisplayTexture(textureBitmap, fname, format);
        }
开发者ID:memerdot,项目名称:puyotools-1,代码行数:7,代码来源:TextureViewer.cs


示例5: GetDXT

        public static void GetDXT(Texture2D texture, int i, byte[] bytes, TextureFormat format)
        {
            Color32[] colors = texture.GetPixels32(i);
            uint w = (uint) texture.width>>i;
            uint h = (uint) texture.height>>i;

            ColorBlock rgba = new ColorBlock();
            BlockDXT1 block1 = new BlockDXT1();
            BlockDXT5 block5 = new BlockDXT5();

            int blocksize = format == TextureFormat.DXT1 ? 8 : 16;
            int index = 0;
            for (uint y = 0; y < h; y += 4) {
                for (uint x = 0; x < w; x += 4) {
                    rgba.init(w, h, colors, x, y);

                    if (format == TextureFormat.DXT1)
                    {
                        QuickCompress.compressDXT1(rgba, block1);
                        block1.WriteBytes(bytes, index);
                    }
                    else
                    {
                        QuickCompress.compressDXT5(rgba, block5, 0);
                        block5.WriteBytes(bytes, index);
                    }

                    index += blocksize;
                }
            }
        }
开发者ID:rbray89,项目名称:ActiveTextureManagement,代码行数:31,代码来源:TextureTools.cs


示例6: GetPixelSize

 public static uint GetPixelSize(TextureFormat textureFormat, int width, int height)
 {
     switch (textureFormat)
     {
         case TextureFormat.Rgba8:
             return (uint)(4 * width * height);
         case TextureFormat.Rgb8:
             return (uint)(3 * width * height);
         case TextureFormat.Rgb5551:
         case TextureFormat.Rgb565:
         case TextureFormat.Rgba4:
         case TextureFormat.La8:
         case TextureFormat.Hilo8:
             return (uint)(2 * width * height);
         case TextureFormat.L8:
         case TextureFormat.A8:
         case TextureFormat.La4:
             return (uint)(1 * width * height);
         case TextureFormat.L4: //TODO: Verify this is correct
         case TextureFormat.A4:
             return (uint)((1 * width * height) / 2);
         case TextureFormat.Etc1:
             return (uint)Etc.GetEtc1Length(new Size(width, height), false);
         case TextureFormat.Etc1A4:
             return (uint)Etc.GetEtc1Length(new Size(width, height), true);
         default:
             throw new Exception("Unsupported Texture Format " + (int)textureFormat);
     }
 }
开发者ID:SciresM,项目名称:FEAT,代码行数:29,代码来源:Texture.cs


示例7: CreateBitmapFromTexture

        /// <summary>
        /// Creates a bitmap from the currently bound texture
        /// </summary>
        public static unsafe Bitmap CreateBitmapFromTexture( int target, int level, TextureFormat format )
        {
            int width = GetTextureLevelParameterInt32( target, level, Gl.GL_TEXTURE_WIDTH );
            int height = GetTextureLevelParameterInt32( target, level, Gl.GL_TEXTURE_HEIGHT );

            GraphicsLog.Verbose( "Creating bitmap from level {0} in {1}x{2} {3} texture", level, width, height, format );

            if ( ( format == TextureFormat.Depth16 ) || ( format == TextureFormat.Depth24 ) || ( format == TextureFormat.Depth32 ) )
            {
                return CreateBitmapFromDepthTexture( target, level, width, height );
            }

            //	Handle colour textures

            //	Get texture memory
            int bytesPerPixel = TextureFormatInfo.GetSizeInBytes( format );
            TextureInfo info = CheckTextureFormat( format );
            byte[] textureMemory = new byte[ width * height * bytesPerPixel ];
            Gl.glGetTexImage( Gl.GL_TEXTURE_2D, level, info.GlFormat, info.GlType, textureMemory );

            //	TODO: Same problem as above...

            //	Create a Bitmap object from image memory
            fixed ( byte* textureMemoryPtr = textureMemory )
            {
                //	TODO: Add per-case check of Format - in cases with no mapping (see TextureFormatToPixelFormat()), do a manual conversion
                return new Bitmap( width, height, width * bytesPerPixel, TextureFormatInfo.ToPixelFormat( format ), ( IntPtr )textureMemoryPtr );
            }
        }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:32,代码来源:OpenGlTexture2dBuilder.cs


示例8: LoadVolumeFromFile

    public static Texture3D LoadVolumeFromFile(string fileName, TextureFormat format, int elementSize ,int width, int height, int depth)
    {
        BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read));
        Texture3D noiseTex = new Texture3D(width, height, depth, TextureFormat.RGBA32, false);
        noiseTex.filterMode = FilterMode.Bilinear;
        noiseTex.wrapMode = TextureWrapMode.Repeat;

        int numElements = width * height * depth;
        List<Color> colors = new List<Color>(numElements);


        // Get pixels from 2d texture for each slize in z direction
        for (int z = 0; z < depth; z++)
        {
            Texture2D tex2d = LoadTexture2DRaw(br, width, height, format, elementSize);
            colors.AddRange(tex2d.GetPixels());
        }
        //colors should now be filled with all pixels
        noiseTex.SetPixels(colors.ToArray());
        noiseTex.Apply(false);

        br.Close();
        return noiseTex;
   
    }
开发者ID:Mymicky,项目名称:MarchingCubesUnity,代码行数:25,代码来源:Helper.cs


示例9: Create

 /// <summary>
 /// Creates the texture data
 /// </summary>
 public void Create( int width, int height, TextureFormat format )
 {
     m_Width = width;
     m_Height = height;
     m_Format = format;
     m_Data = new byte[ width * height * TextureFormatInfo.GetSizeInBytes( format ) ];
 }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:10,代码来源:Texture2dData.cs


示例10: ConvertDown

        public Corona.Image ConvertDown(Corona.Image sourceImage, TextureFormat toFormat)
        {
            int bits = -1;
            if (toFormat == TextureFormat.Format2_I2) bits = 2;
            if (toFormat == TextureFormat.Format3_I4) bits = 4;
            if (toFormat == TextureFormat.Format4_I8) bits = 8;
            if (toFormat == TextureFormat.Format7_16bpp) bits = 16;

            int colors = 1<<bits;

            Corona.Image ret = null;

            using (Util.TempFile tmpIn = new Util.TempFile("png"), tmpOut = new Util.TempFile("png"))
            {
                sourceImage.Save(tmpIn.Path, Corona.FileFormat.PNG);

                string output = Run("-treedepth", 4, "-colors", colors, tmpIn, tmpOut);

                if (toFormat == TextureFormat.Format7_16bpp)
                    ret = Corona.Image.Open(tmpOut.Path, Corona.PixelFormat.R8G8B8A8, Corona.FileFormat.PNG);
                else
                    ret = Corona.Image.Open(tmpOut.Path, Corona.PixelFormat.I8, Corona.FileFormat.PNG);

            }
            return ret;
        }
开发者ID:mtheall,项目名称:DS3dbugger,代码行数:26,代码来源:ImageMagick.cs


示例11: GetScreenBytes

 public static byte[] GetScreenBytes(TextureFormat textureFormat)
 {
     Texture2D screenTexture = new Texture2D(Screen.width, Screen.height,textureFormat,true);
     screenTexture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height),0,0);
     screenTexture.Apply();
     byte[] byteArray = screenTexture.EncodeToPNG();
     return byteArray;
 }
开发者ID:shawmakesmusic,项目名称:leo,代码行数:8,代码来源:SPAndroidShare.cs


示例12: TileMeshSettings

		public TileMeshSettings (IVector2 tiles, int tileResolution, float tileSize, MeshMode meshMode, TextureFormat textureFormat)
		{
			Tiles			= tiles;
			TileResolution	= tileResolution;
			TileSize		= tileSize;
			MeshMode		= meshMode;
			TextureFormat	= textureFormat;
		}
开发者ID:DarkXenoShark,项目名称:AI-ICA2-RTS,代码行数:8,代码来源:TileMeshSettings.cs


示例13: YUVTexture

 /// <summary>
 /// Initializes a new instance of the <see cref="Tango.YUVTexture"/> class.
 /// NOTE : Texture resolutions will be reset by the API. The sizes passed
 /// into the constructor are not guaranteed to persist when running on device.
 /// </summary>
 /// <param name="width">Width.</param>
 /// <param name="height">Height.</param>
 /// <param name="format">Format.</param>
 /// <param name="mipmap">If set to <c>true</c> mipmap.</param>
 public YUVTexture(int yPlaneWidth, int yPlaneHeight,
                   int uvPlaneWidth, int uvPlaneHeight,
                   TextureFormat format, bool mipmap)
 {
     m_videoOverlayTextureY = new Texture2D(yPlaneWidth, yPlaneHeight, format, mipmap);
     m_videoOverlayTextureCb = new Texture2D(uvPlaneWidth, uvPlaneHeight, format, mipmap);
     m_videoOverlayTextureCr = new Texture2D(uvPlaneWidth, uvPlaneHeight, format, mipmap);
 }
开发者ID:nigelDaMan,项目名称:WeCanTango,代码行数:17,代码来源:VideoOverlayProvider.cs


示例14: Texture2DInfo

	public Texture2DInfo(int width, int height, TextureFormat format, bool hasMipmaps, byte[] rawData)
	{
		this.width = width;
		this.height = height;
		this.format = format;
		this.hasMipmaps = hasMipmaps;
		this.rawData = rawData;
	}
开发者ID:ozonexo3,项目名称:FAForeverMapEditor,代码行数:8,代码来源:Texture2DInfo.cs


示例15: TileMeshSettings

 public TileMeshSettings(int tilesX, int tilesY, int tileResolution, float tileSize, MeshMode meshMode, TextureFormat textureFormat)
 {
     TilesX = tilesX;
     TilesY = tilesY;
     TileResolution = tileResolution;
     TileSize = tileSize;
     MeshMode = meshMode;
     TextureFormat = textureFormat;
 }
开发者ID:ntl92bk,项目名称:UnityTileMap,代码行数:9,代码来源:TileMeshSettings.cs


示例16: GetBitsPerPixel

 public static int GetBitsPerPixel(TextureFormat format)
 {
     switch (format)
     {
     case TextureFormat.Alpha8: //	 Alpha-only texture format.
         return 8;
     case TextureFormat.ARGB4444: //	 A 16 bits/pixel texture format. Texture stores color with an alpha channel.
         return 16;
     case TextureFormat.RGBA4444: //	 A 16 bits/pixel texture format.
         return 16;
     case TextureFormat.RGB24:	// A color texture format.
         return 24;
     case TextureFormat.RGBA32:	//Color with an alpha channel texture format.
         return 32;
     case TextureFormat.ARGB32:	//Color with an alpha channel texture format.
         return 32;
     case TextureFormat.RGB565:	//	 A 16 bit color texture format.
         return 16;
     case TextureFormat.DXT1:	// Compressed color texture format.
         return 4;
     case TextureFormat.DXT5:	// Compressed color with alpha channel texture format.
         return 8;
         /*
         case TextureFormat.WiiI4:	// Wii texture format.
         case TextureFormat.WiiI8:	// Wii texture format. Intensity 8 bit.
         case TextureFormat.WiiIA4:	// Wii texture format. Intensity + Alpha 8 bit (4 + 4).
         case TextureFormat.WiiIA8:	// Wii texture format. Intensity + Alpha 16 bit (8 + 8).
         case TextureFormat.WiiRGB565:	// Wii texture format. RGB 16 bit (565).
         case TextureFormat.WiiRGB5A3:	// Wii texture format. RGBA 16 bit (4443).
         case TextureFormat.WiiRGBA8:	// Wii texture format. RGBA 32 bit (8888).
         case TextureFormat.WiiCMPR:	//	 Compressed Wii texture format. 4 bits/texel, ~RGB8A1 (Outline alpha is not currently supported).
             return 0;  //Not supported yet
         */
     case TextureFormat.PVRTC_RGB2://	 PowerVR (iOS) 2 bits/pixel compressed color texture format.
         return 2;
     case TextureFormat.PVRTC_RGBA2://	 PowerVR (iOS) 2 bits/pixel compressed with alpha channel texture format
         return 2;
     case TextureFormat.PVRTC_RGB4://	 PowerVR (iOS) 4 bits/pixel compressed color texture format.
         return 4;
     case TextureFormat.PVRTC_RGBA4://	 PowerVR (iOS) 4 bits/pixel compressed with alpha channel texture format
         return 4;
     case TextureFormat.ETC_RGB4://	 ETC (GLES2.0) 4 bits/pixel compressed RGB texture format.
         return 4;
     case TextureFormat.ATC_RGB4://	 ATC (ATITC) 4 bits/pixel compressed RGB texture format.
         return 4;
     case TextureFormat.ATC_RGBA8://	 ATC (ATITC) 8 bits/pixel compressed RGB texture format.
         return 8;
     case TextureFormat.BGRA32://	 Format returned by iPhone camera
         return 32;
     // case TextureFormat.ATF_RGB_DXT1://	 Flash-specific RGB DXT1 compressed color texture format.
     // case TextureFormat.ATF_RGBA_JPG://	 Flash-specific RGBA JPG-compressed color texture format.
     // case TextureFormat.ATF_RGB_JPG://	 Flash-specific RGB JPG-compressed color texture format.
     // 	return 0; //Not supported yet
     }
     return 0;
 }
开发者ID:zhukunqian,项目名称:usmooth,代码行数:56,代码来源:UsTextureUtil.cs


示例17: HasAlphaChannel

 /// <summary>
 /// Returns true if the specified texture format supports an alpha channel
 /// </summary>
 public static bool HasAlphaChannel( TextureFormat texFormat )
 {
     switch ( texFormat )
     {
         case TextureFormat.R8G8B8A8:
         case TextureFormat.B8G8R8A8:
         case TextureFormat.A8R8G8B8:
         case TextureFormat.A8B8G8R8: return true;
     }
     return false;
 }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:14,代码来源:TextureFormat.cs


示例18: getTextureFormat

 public static bool getTextureFormat(ref TextureFormat result, SerializedObject serialTex)
 {
     if(serialTex == null) return false;
     SerializedProperty prop = serialTex.FindProperty("m_TextureFormat");
     if( prop != null ) {
         result = (TextureFormat)prop.intValue;
         return true;
     }
     Debug.LogError("m_TextureFormat SerializedProperty not found!");
     return false;
 }
开发者ID:elephantatwork,项目名称:Secret-Game,代码行数:11,代码来源:AssetUtil.cs


示例19: LoadFixedHeightFromFile

		// Load a texture with the specified height and calculating width by respecting the aspect ratio
		public static Texture2D LoadFixedHeightFromFile(string filePath, int fixedHeight, TextureFormat textureFormat = TextureFormat.R16)
		{
			Vector2 imageSize = ImageHelper.GetDimensions(filePath);
			float width = fixedHeight;
			if (imageSize.y != 0)
			{
				width = imageSize.x * fixedHeight / imageSize.y;
			}
			
			return LoadFromFile(filePath, (int)width, fixedHeight, textureFormat);
		}
开发者ID:adamtelfer,项目名称:idlecraft,代码行数:12,代码来源:TextureUtils.cs


示例20: LoadImage

 public static IEnumerator LoadImage(this Texture2D texture2D, string url, Vector2 size, TextureFormat format = TextureFormat.RGB24, bool mipmap = false)
 {
     Texture2D tex = new Texture2D((int)size.x, (int)size.y, format, mipmap);
     WWW www = new WWW(url);
     yield return www;
     if (string.IsNullOrEmpty(www.error))
     {
         www.LoadImageIntoTexture(tex);
         texture2D = tex;
     }
 }
开发者ID:quangthinhnguyen,项目名称:Unity3d-AMCore,代码行数:11,代码来源:TextureExtension.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TextureLoader类代码示例发布时间:2022-05-24
下一篇:
C# TextureFlags类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap