Babybus-u3d技术交流-照片外边加相框并存储
public static void SavePicture(GameObject xiangkuang, GameObject zhaopian, string datapath)
{
Texture2D XiangkuangTexture;
//相框
Texture2D ZhaopianTexture;
//照片
XiangkuangTexture = (Texture2D)xiangkuang.GetComponent<UI2DSprite
().mainTexture;
ZhaopianTexture = (Texture2D)zhaopian.GetComponent<UI2DSprite>().mainTexture;
Texture2D SaveTexture = new Texture2D(XiangkuangTexture.width, XiangkuangTexture.height, TextureFormat.ARGB32,
false
);
//SaveTexture = XiangkuangTexture;
int PicStartwidth = (XiangkuangTexture.width - ZhaopianTexture.width) / 2;
int PicStartheight = (XiangkuangTexture.height - ZhaopianTexture.height) / 2;
//左侧
for (int i = 0; i < PicStartwidth; i++)
{
for (int j = 0; j < XiangkuangTexture.height; j++)
{
SaveTexture.SetPixel(i, j, XiangkuangTexture.GetPixel(i, j));
}
}
//右侧
for (int i = PicStartwidth + ZhaopianTexture.width; i < PicStartwidth + XiangkuangTexture.width; i++)
{
for (int j = 0; j < XiangkuangTexture.height; j++)
{
SaveTexture.SetPixel(i, j, XiangkuangTexture.GetPixel(i, j));
}
}
//上侧
for (int i = PicStartwidth; i < ZhaopianTexture.width+PicStartwidth; i++)
{ for (int j = ZhaopianTexture.height + PicStartheight; j < XiangkuangTexture.height; j++)
{
SaveTexture.SetPixel(i, j, XiangkuangTexture.GetPixel(i, j));
}
}
//下侧
for (int i = PicStartwidth; i < ZhaopianTexture.width + PicStartwidth; i++)
{
for (int j = 0; j < PicStartheight; j++)
{
SaveTexture.SetPixel(i, j, XiangkuangTexture.GetPixel(i, j));
}
}
//图片
for (int i = 0; i < ZhaopianTexture.width; i++)
{
for(intj = 0; j < ZhaopianTexture.height; j++)
{
SaveTexture.SetPixel(i + PicStartwidth, j + PicStartheight, ZhaopianTexture.GetPixel(i, j));
}
}
SaveTexture.Apply();
byte[] bytes = SaveTexture.EncodeToPNG();
string
filename = datapath + "/" + GlobalManager.createshadow_toy + photoNum +
".png";
System.IO.File.WriteAllBytes(filename, bytes);
}
已存在贴图需要满足
本来如果美术给的图片是ARPG32的png图片的话有更简便的方法,但是现在还不太清楚RPGA4444怎么转换成ARPG32,先mark下,了解改进方法再修改吧。