Changing color of Texture2d with transparency


I would like to change the color of the texture 2d image drawn in OnGUI function using GUI.drawtexture. When i change the color using get & set pixel functionality, color of whole image immaterial of its transparency area changed. I would like to change the color of non transparent area alone.

public Texture2D baseTex;
public Color colors = new Color[1];

void Start()
colors = Color.cyan;

 int mipCount = Mathf.Min(1, baseTex.mipmapCount);
	// tint each mip level
	for( var mip = 0; mip < mipCount; ++mip ) 
		var cols = baseTex.GetPixels( mip );
		for( var i = 0; i < cols.Length; ++i ) 
			cols _= Color.Lerp(cols*, colors[mip], 1f);*_

* }*
* baseTex.SetPixels( cols, mip );*
* }*
* // actually apply all SetPixels, don’t recalculate mip levels*
* baseTex.Apply(false);*
void OnGUI()
GUI.DrawTexture(new Rect(100, 0, baseTex.width * zoom, baseTex.height * zoom), baseTex);
When i apply the texture in a transparent material its working fine, but i need to draw the color changed texture in OnGUI. Please help me out to resolve the issue.

Unless I’m misunderstanding the question, you want to change only non-transparent pixels?

I believe that should be as easy as a simple IF statement, using the pixel’s ALPHA.

if(alpha = 255)

else {