Texture2D bgTex = Instantiate(Resources.Load<Texture2D>("TW1")); //背景图 Texture2D codeColors = DrawQRCode.DrawCode_Texture2D(StaticData.bindURL + StaticData.userId, 256, 256); Color32[] erweima= codeColors.GetPixels32(); Texture2D newTex = new Texture2D(200, 200); for (int i = 29; i < 228; i++) { for (int j = 29; j < 228; j++) { newTex.SetPixel(i - 29, j - 29, codeColors.GetPixel(i, j)); } } bgTex.SetPixels32(250, 480, 256, 256, GetPingPuT2d(newTex, new Vector2(256, 256), 1.3f).GetPixels32()); bgTex.Apply(); // DrawQRCode.SaveImage(bgTex, Application.dataPath, "合成图");//pc端测试 byte[] bytes = bgTex.EncodeToJPG(); string filename = Application.persistentDataPath + "/shareMain.jpg"; Debug.Log(filename); System.IO.File.WriteAllBytes(filename, bytes); content.SetImagePath(filename); content.SetShareType(ContentType.Image); ssdk.ShareContent(PlatformType.WeChat, content); } public Texture2D GetPingPuT2d(Texture2D t2d, Vector2 rect, float scale = 1f) { scale = 1 / scale; //t2d = MyTextureTools.ScaleTexture(t2d,(int)(t2d.width*scale),(int )(t2d.height*scale)) ; Texture2D result = new Texture2D((int)rect.x, (int)rect.y, t2d.format, false); for (int i = 0; i < result.width; i++) { for (int j = 0; j < result.height; j++) { result.SetPixel(i, j, t2d.GetPixel((int)((i * scale) % (t2d.width)), (int)((j * scale) % (t2d.height)))); } } result.Apply(); return result; }