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


C# Texture2D.Resize方法代码示例

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


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

示例1: CropTexture

 public static void CropTexture(Texture2D tex, int x, int y, int width, int height)
 {
     var newPixels = tex.GetPixels(x, y, width, height);
     tex.Resize(width, height);
     tex.SetPixels(newPixels);
     tex.Apply();
 }
开发者ID:SamsamTS,项目名称:CitiesSkylinesAssetIconsMod,代码行数:7,代码来源:IconModifier.cs

示例2: Read

    /// <summary>
    /// Reads from the provided file name all parameters and data for a
    /// heightmap.  If the data for the heightmap does not exist, then
    /// no data is written to the provided texture.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> that will store read-in parameters.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> that will store read-in parameters for
    /// <see cref="CloudFractal" />.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" />  that will store read-in parameters for
    /// <see cref="WorleyNoise" />.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Read(string fileName, ref NormalOptions no,
	                        ref CloudOptions co, ref VoronoiOptions vo,
							ref Texture2D tex)
    {
        using(BinaryReader r = new BinaryReader(File.OpenRead(fileName)))
        {
            no.size = r.ReadInt32();
            no.seed = r.ReadInt32();
            no.cloudInf = r.ReadSingle();
            no.voronoiInf = r.ReadSingle();
            no.useThermalErosion = r.ReadBoolean();
            no.useHydroErosion = r.ReadBoolean();
            no.showSeams = r.ReadBoolean();

            co.upperLeftStart = r.ReadSingle();
            co.lowerLeftStart = r.ReadSingle();
            co.lowerRightStart = r.ReadSingle();
            co.upperRightStart = r.ReadSingle();

            vo.metric = (DistanceFunctions.DistanceMetric)r.ReadInt32();
            vo.combiner = (CombinerFunctions.CombineFunction)r.ReadInt32();
            vo.numberOfFeaturePoints = r.ReadInt32();
            vo.numberOfSubregions = r.ReadInt32();
            vo.multiplier = r.ReadSingle();

            tex.Resize(no.size, no.size);
            int bLeft = (int)(r.BaseStream.Length - r.BaseStream.Position);
            if(bLeft > 0)
                tex.LoadImage(r.ReadBytes(bLeft));
        }
    }
开发者ID:seflopod,项目名称:EarthMake,代码行数:53,代码来源:HeightMapSerializer.cs

示例3: Start

    void Start()
    {
        Renderer rend = GetComponent<Renderer>();

        // duplicate the original texture and assign to the material
        tex = Instantiate(rend.material.mainTexture) as Texture2D;
        tex.Resize (200, 100);
        rend.material.mainTexture = tex;

        // colors used to tint the first 3 mip levels
        Color[] colors = new Color[3];
        colors[0] = Color.red;
        colors[1] = Color.green;
        colors[2] = Color.blue;
         mipCount = Mathf.Min(3, tex.mipmapCount);

        // tint each mip level
        for( var mip = 0; mip < mipCount; ++mip ) {
            var cols = tex.GetPixels( mip );
            for( var i = 0; i < cols.Length; ++i ) {
                cols[i] = new Color(Random.value,Random.value,Random.value);
            }
            tex.SetPixels( cols, mip );
        }
        // actually apply all SetPixels, don't recalculate mip levels
        tex.Apply(false);
        int length = tex.GetPixels ().Length;
        wat = new float[length];
        for (int i =0; i< wat.Length; i++)
            wat [i] = Random.value;
        Debug.Log ("n minmaps: " + mipCount);

        //for(int i =0; i< wa
    }
开发者ID:AVUIs,项目名称:un1c0rn3r,代码行数:34,代码来源:MuhShader.cs

示例4: Awake

 private void Awake()
 {
     bricksContainer = new GameObject("Bricks").transform;
     brickTexture = TextureE.whitePixel;
     brickTexture.Resize(brickWidth, brickHeight);
     brickSprite = Sprite.Create(brickTexture, new Rect(0, 0, brickWidth, brickHeight), new Vector2(0.5f, 0.5f));
     material = new PhysicsMaterial2D {name = "Bouncy", bounciness = 1, friction = 0};
     GeneratePaddle();
     GenerateBorders();
 }
开发者ID:liamzebedee,项目名称:hackagong2015,代码行数:10,代码来源:Breakout.cs

示例5: scale

    /// <summary>
    /// Scales the texture data of the given texture.
    /// </summary>
    /// <param name="tex">Texure to scale</param>
    /// <param name="width">New width</param>
    /// <param name="height">New height</param>
    /// <param name="mode">Filtering mode</param>
    public static void scale(Texture2D tex, int width, int height, FilterMode mode = FilterMode.Trilinear)
    {
        Rect texR = new Rect(0, 0, width, height);
        _gpu_scale(tex, width, height, mode);

        // Update new texture
        tex.Resize(width, height);
        tex.ReadPixels(texR, 0, 0, true);
        tex.Apply(true);        //Remove this if you hate us applying textures for you :)
    }
开发者ID:Meragon,项目名称:Unity-WinForms,代码行数:17,代码来源:TextureScaler.cs

示例6: scaled

    /// <summary>
    ///     Returns a scaled copy of given texture.
    /// </summary>
    /// <param name="tex">Source texure to scale</param>
    /// <param name="width">Destination texture width</param>
    /// <param name="height">Destination texture height</param>
    /// <param name="mode">Filtering mode</param>
    public static Texture2D scaled(Texture2D src, int width, int height, FilterMode mode = FilterMode.Trilinear)
    {
        Rect texR = new Rect(0, 0, width, height);
        _gpu_scale(src, width, height, mode);

        //Get rendered data back to a new texture
        Texture2D result = new Texture2D(width, height, TextureFormat.ARGB32, true);
        result.Resize(width, height);
        result.ReadPixels(texR, 0, 0, true);
        return result;
    }
开发者ID:Meragon,项目名称:Unity-WinForms,代码行数:18,代码来源:TextureScaler.cs

示例7: ScaleTexture

 public static void ScaleTexture(Texture2D tex, int width, int height)
 {
     var newPixels = new Color[width * height];
     for (int y = 0; y < height; ++y)
     {
         for (int x = 0; x < width; ++x)
         {
             newPixels[y * width + x] = tex.GetPixelBilinear(((float)x) / width, ((float)y) / height);
         }
     }
     tex.Resize(width, height);
     tex.SetPixels(newPixels);
     tex.Apply();
 }
开发者ID:SamsamTS,项目名称:CitiesSkylinesAssetIconsMod,代码行数:14,代码来源:IconModifier.cs

示例8: ThreadedScale

	private static void ThreadedScale(Texture2D tex, int newWidth, int newHeight, bool useBilinear) {
		texColors = tex.GetPixels();
		newColors = new Color[newWidth * newHeight];
		if (useBilinear) {
			ratioX = 1.0f / ((float)newWidth / (tex.width - 1));
			ratioY = 1.0f / ((float)newHeight / (tex.height - 1));
		} else {
			ratioX = ((float)tex.width) / newWidth;
			ratioY = ((float)tex.height) / newHeight;
		}
		w = tex.width;
		w2 = newWidth;
		var cores = Mathf.Min(SystemInfo.processorCount, newHeight);
		var slice = newHeight / cores;

		finishCount = 0;
		if (mutex == null) {
			mutex = new Mutex(false);
		}
		if (cores > 1) {
			int i = 0;
			ThreadData threadData;
			for (i = 0; i < cores - 1; i++) {
				threadData = new ThreadData(slice * i, slice * (i + 1));
				ParameterizedThreadStart ts = useBilinear ? new ParameterizedThreadStart(BilinearScale) : new ParameterizedThreadStart(PointScale);
				Thread thread = new Thread(ts);
				thread.Start(threadData);
			}
			threadData = new ThreadData(slice * i, newHeight);
			if (useBilinear) {
				BilinearScale(threadData);
			} else {
				PointScale(threadData);
			}
			while (finishCount < cores) {
				Thread.Sleep(1);
			}
		} else {
			ThreadData threadData = new ThreadData(0, newHeight);
			if (useBilinear) {
				BilinearScale(threadData);
			} else {
				PointScale(threadData);
			}
		}

		tex.Resize(newWidth, newHeight);
		tex.SetPixels(newColors);
		tex.Apply();
	}
开发者ID:DiarmuidByrne,项目名称:Captain-Cillian,代码行数:50,代码来源:TextureScale.cs

示例9: Resize

		/// <summary>Resize the given image with the given scale ratio.</summary>
		public static Texture2D Resize(Texture2D original,float ratio){
			
			// Get the original size:
			int maxY=original.height;
			int maxX=original.width;
			
			// What's the target size?
			int height=(int)(maxY * ratio);
			int width=(int)(maxX * ratio);
			
			if(height==maxY && width==maxX){
				
				// Unchanged:
				return original;
				
			}
			
			Color32[] texColors = original.GetPixels32();
			Color32[] newColors = new Color32[width * height];
			
			float ratioX = 1f / ((float)width / (float)(maxX-1));
			float ratioY = 1f / ((float)height / (float)(maxY-1));
			
			for (int y = 0; y < height; y++) {
				
				int yFloor = (int)Mathf.Floor (y * ratioY);
				int y1 = yFloor * maxX;
				int y2 = (yFloor+1) * maxX;
				int yw = y * width;
		 
				for (int x = 0; x < width; x++){
					int xFloor = (int)Mathf.Floor (x * ratioX);
					float xLerp = x * ratioX-xFloor;
					newColors[yw + x] = ColorLerpUnclamped (ColorLerpUnclamped (texColors[y1 + xFloor], texColors[y1 + xFloor+1], xLerp),
															ColorLerpUnclamped (texColors[y2 + xFloor], texColors[y2 + xFloor+1], xLerp),
															y*ratioY-yFloor);
				}
			}
			
			original.Resize(width,height,TextureFormat.ARGB32,false);
			
			original.SetPixels32(newColors);
			
			// Flush the texture:
			original.Apply();
			
			// Return it:
			return original;
			
		}
开发者ID:KMarshland,项目名称:ChildrensHospitalApp,代码行数:51,代码来源:ImageResizer.cs

示例10: Resize

		public static void Resize(Texture2D texture, int width, int height)
		{
			Color[] pixelArray = new Color[width * height];
			float incX = (1.0f / (float)width);
			float incY = (1.0f / (float)height); 
			
			for (int px = 0; px < pixelArray.Length; px++)
			{ 
				pixelArray[px] = texture.GetPixelBilinear(incX * ((float)px % width), incY * ((float)Mathf.Floor(px / width))); 
			}
			
			texture.Resize(width, height);
			texture.SetPixels(pixelArray, 0); 
			texture.Apply();
		}
开发者ID:adamtelfer,项目名称:idlecraft,代码行数:15,代码来源:TextureUtils.cs

示例11: ThreadedScale

 private static void ThreadedScale(Texture2D tex, int newWidth, int newHeight)
 {
     TextureScale.texColors = tex.GetPixels();
     TextureScale.newColors = new Color[newWidth * newHeight];
     TextureScale.ratioX = (float)tex.width / (float)newWidth;
     TextureScale.ratioY = (float)tex.height / (float)newHeight;
     TextureScale.w = tex.width;
     TextureScale.w2 = newWidth;
     TextureScale.finishCount = 0;
     if (TextureScale.mutex == null)
     {
         TextureScale.mutex = new Mutex(false);
     }
     TextureScale.PointScale(0, newHeight);
     tex.Resize(newWidth, newHeight);
     tex.SetPixels(TextureScale.newColors);
     tex.Apply();
 }
开发者ID:Leloman4345,项目名称:uGoldSource,代码行数:18,代码来源:TextureScale.cs

示例12: Start

 // Use this for initialization
 void Start()
 {
     rend = GetComponent<Renderer> ();
     tex = new Texture2D (1,1,TextureFormat.RGBAFloat,false);
     rend.material.mainTexture = tex;
     TactonicDeviceList dl = Tactonic.GetDeviceList ();
     if (dl.GetNumDevices () > id) {
         device = dl.GetDevice (id);
         Debug.Log ("id: " + id + ", serial number: " + device.serialNumber);
         frame = new TactonicFrame (device);
         Tactonic.AddFrameCallback (device, this);
         Tactonic.StartDevice (device);
         newFrame = false;
         tex.Resize (device.GetRows (), device.GetCols ());
         Debug.Log ("rows: " + device.GetRows() + ", cols: " + device.GetCols());
     } else {
         Debug.Log ("id " + id + " not found! " + dl.GetNumDevices () + " devices found.");
     }
 }
开发者ID:nyu-vr-research,项目名称:vive-holojam,代码行数:20,代码来源:TactonicObject.cs

示例13: GenerateToTexture

        /// <summary>
        /// Renders the given material into the given render target using a full-screen quad.
        /// Assumes the material uses a shader generated from a Graph.
        /// Optionally copies the resulting texture data into a Texture2D for further processing.
        /// </summary>
        /// <param name="rendTarget">
        /// If set to "null", the noise will be rendered onto the screen.
        /// </param>
        public static void GenerateToTexture(RenderTexture rendTarget, Material noiseMat,
											 Texture2D copyTo = null)
        {
            int width = (rendTarget == null ? Screen.width : rendTarget.width),
                height = (rendTarget == null ? Screen.height : rendTarget.height);

            //Set up rendering state.
            RenderTexture activeTarget = RenderTexture.active;
            RenderTexture.active = rendTarget;
            noiseMat.SetPass(0);

            //Render a quad using immediate mode.
            GL.PushMatrix();
            GL.LoadIdentity();
            GL.Viewport(new Rect(0, 0, width, height));
            GL.Begin(GL.TRIANGLE_STRIP);
            GL.Color(Color.white);
            GL.TexCoord(new Vector3(0.0f, 0.0f, 0.0f));
            GL.Vertex3(-1.0f, -1.0f, 0.0f);
            GL.TexCoord(new Vector3(1.0f, 0.0f, 0.0f));
            GL.Vertex3(1.0f, -1.0f, 0.0f);
            GL.TexCoord(new Vector3(0.0f, 1.0f, 0.0f));
            GL.Vertex3(-1.0f, 1.0f, 0.0f);
            GL.TexCoord(new Vector3(1.0f, 1.0f, 0.0f));
            GL.Vertex3(1.0f, 1.0f, 0.0f);
            GL.End();
            GL.PopMatrix();

            //Copy the results into the Texture2D.
            if (copyTo != null)
            {
                if (copyTo.width != width || copyTo.height != height)
                    copyTo.Resize(width, height);

                copyTo.ReadPixels(new Rect(0, 0, width, height), 0, 0);
                copyTo.Apply();
            }

            //Reset rendering state.
            RenderTexture.active = activeTarget;
        }
开发者ID:heyx3,项目名称:GPUNoiseForUnity,代码行数:49,代码来源:GraphUtils.cs

示例14: CopyToTexture

    public override void CopyToTexture(Texture2D texture2D)
    {
        var format = ConvertPixelFormat(mPixelFormat);
        if (texture2D.width != mWidth || texture2D.height != mHeight || format != texture2D.format)
        {
            texture2D.Resize(mWidth, mHeight, format, false);
        }
        var channels = 1;
        switch (mPixelFormat)
        {
            case PIXEL_FORMAT.RGBA8888:
                channels = 4;
                break;
            case PIXEL_FORMAT.RGB565:
            case PIXEL_FORMAT.RGB888:
                channels = 3;
                break;
        }
        var colors = texture2D.GetPixels();
        var c = 0;
        for (var i = 0; i < colors.Length; i++)
        {
            for (var j = 0; j < channels; j++)
                colors[i][j] = mData[c++]/255.0f;
            for (var j = channels; j < 4; j++)
                colors[i][j] = colors[i][j - 1];
        }

        texture2D.SetPixels(colors);
    }
开发者ID:carrizofm2010,项目名称:app012-acuariotribuno,代码行数:30,代码来源:ImageImpl.cs

示例15: PackTextures

	public static Rect[] PackTextures (Texture2D texture, Texture2D[] textures, int width, int height, int padding, int maxSize)
	{
		if (width > maxSize && height > maxSize) return null;
		if (width > maxSize || height > maxSize) { int temp = width; width = height; height = temp; }
		
		// Force square by sizing up
		if (NGUISettings.forceSquareAtlas)
		{
			if (width > height)
				height = width;
			else if (height > width)
				width = height;
		}
		UITexturePacker bp = new UITexturePacker(width, height, false);
		Storage[] storage = new Storage[textures.Length];

		for (int i = 0; i < textures.Length; i++)
		{
			Texture2D tex = textures[i];
			if (!tex) continue;

			Rect rect = new Rect();

			int xPadding = 1;
			int yPadding = 1;

			for (xPadding = 1; xPadding >= 0; --xPadding)
			{
				for (yPadding = 1; yPadding >= 0; --yPadding)
				{
					rect = bp.Insert(tex.width + (xPadding * padding), tex.height + (yPadding * padding),
						UITexturePacker.FreeRectChoiceHeuristic.RectBestAreaFit);
					if (rect.width != 0 && rect.height != 0) break;

					// After having no padding if it still doesn't fit -- increase texture size.
					else if (xPadding == 0 && yPadding == 0)
					{
						return PackTextures(texture, textures, width * (width <= height ? 2 : 1),
							height * (height < width ? 2 : 1), padding, maxSize);
					}
				}
				if (rect.width != 0 && rect.height != 0) break;
			}

			storage[i] = new Storage();
			storage[i].rect = rect;
			storage[i].paddingX = (xPadding != 0);
			storage[i].paddingY = (yPadding != 0);
		}

		texture.Resize(width, height);
		texture.SetPixels(new Color[width * height]);

		// The returned rects
		Rect[] rects = new Rect[textures.Length];

		for (int i = 0; i < textures.Length; i++)
		{
			Texture2D tex = textures[i];
			if (!tex) continue;

			Rect rect = storage[i].rect;
			int xPadding = (storage[i].paddingX ? padding : 0);
			int yPadding = (storage[i].paddingY ? padding : 0);
			Color[] colors = tex.GetPixels();

			// Would be used to rotate the texture if need be.
			if (rect.width != tex.width + xPadding)
			{
				Color[] newColors = tex.GetPixels();

				for (int x = 0; x < rect.width; x++)
				{
					for (int y = 0; y < rect.height; y++)
					{
						int prevIndex = ((int)rect.height - (y + 1)) + x * (int)tex.width;
						newColors[x + y * (int)rect.width] = colors[prevIndex];
					}
				}

				colors = newColors;
			}

			texture.SetPixels((int)rect.x, (int)rect.y, (int)rect.width - xPadding, (int)rect.height - yPadding, colors);
			rect.x /= width;
			rect.y /= height;
			rect.width = (rect.width - xPadding) / width;
			rect.height = (rect.height - yPadding) / height;
			rects[i] = rect;
		}
		texture.Apply();
		return rects;
	}
开发者ID:jixiang111,项目名称:TTUI-Framework,代码行数:93,代码来源:UITexturePacker.cs


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