Unity生成二维吗 并且取二维吗的中心区域像素 还有texture2D的缩放

 

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;
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值