Unity中手动压缩图片 修改图片分辨率

根据untiy的 Sexpixel 方法   先获取原图的像素点颜色  写入到新的texture2D上   下面示范是将一张1920*1080的图   重写为384+216的图  缩小1/5

public Texture2D t2d;
Texture2D texture = new Texture2D(384, 216, TextureFormat.RGBA32, true);

        for (int i = 0; i < texture.height; i++)//压缩图片
        {
            for (int j = 0; j < texture.width; j++)
            {
                Color color = t2d.GetPixel(j * 5, i * 5);
                texture.SetPixel(j, i, color);
				
            }
        }
        texture.Apply();
        byte[] imagesst = texture.EncodeToJPG();
		File.WriteAllBytes(filepathsst + "/" + lengthpicCam.ToString() + ".jpg", imagesst);

 

你可能感兴趣的:(unity)