- Home /
Merging 2 Textures Into 1
I am trying to merge two textures into one with little sucess. One texture is a border with a UI mask in the middle and the second texture is a picture of the user, taken with the camera of a mobile device. When the user takes the picture it is saved as a photo of him togther with the border. The problem is, I cant really understand who merging 2 textures work. I get an image but the colors are blurry. This is the code I am using:
public class MergeTextures : MonoBehaviour {
public RawImage image;
public Texture2D tex1;
public Texture2D tex2;
public void Merge()
{
Color[] tex1Pix = tex1.GetPixels();
Color[] tex2Pix = tex2.GetPixels();
int width = (tex1.width >= tex2.width) ? tex1.width : tex2.width;
int height = (tex1.height >= tex2.height) ? tex1.height : tex2.height;
Color[] biggerArray = (tex1Pix.Length >= tex2Pix.Length) ? tex1Pix : tex2Pix;
Color[] smallerArray = (biggerArray == tex1Pix) ? tex2Pix : tex1Pix;
for(int i = 0; i < smallerArray.Length; i++)
biggerArray[i] += smallerArray[i];
Texture2D photo = new Texture2D(width, height);
photo.SetPixels(biggerArray);
photo.Apply();
image.texture = photo;
image.SetNativeSize();
}
}
I will appreciate any help!
I don't know what you really want to do but you should take at look at http://homepages.inf.ed.ac.uk/rbf/HIPR2/arthops.htm and http://wiki.unity3d.com/index.php/Blend_2_Textures
You should use texture of same size if you want to use 1D pixels array or loop on 2D array by using GetPixel(int x, int y)
PS : Images are worth 1000 words, especially here
Answer by thepenguinmaster · Dec 10, 2014 at 06:47 PM
Graphics.BlitMultiTap or Graphics.Blit will definately do the trick. You will want to take your materials and transparencies into consideration. For transparency possibly use a decal material when using Graphics.BlitMultiTap.
Just as a warning this will reuire pro.
Your answer
Follow this Question
Related Questions
How can i merge mesh vertices using a script? 2 Answers
How to merge 2 projects into one 1 Answer
solve merge conflict in unity collab 1 Answer