截屏功能-压缩Texture保存本地

public void SaveTexture(string path, Texture2D texture, float scaleValue)
{
float tempX = texture.width;
float tempY = texture.height;
float x = tempX * scaleValue;
float y = tempY * scaleValue;
Texture2D result = new Texture2D(Convert.ToInt32(x), Convert.ToInt32(y), texture.format, false);
//result.filterMode = FilterMode.Bilinear;
for (int i = 0; i < result.height; i++)
{
for (int j = 0; j < result.width; j++)
{

//计算位置的比例,以这个比例在原图提取像素颜色
//GetPixelBilinear(x,y的位置比例来提取这个点的颜色);

Color newColor = texture.GetPixelBilinear((float)j / (float)result.width, (float)i / (float)result.height);
//将提取出来的颜色赋值给这个位置
result.SetPixel(j, i, newColor);
}
}
result.Apply();
byte[] byt = result.EncodeToPNG();
File.WriteAllBytes(path, byt);
Debug.Log("压缩完成");
}

转载于:https://www.cnblogs.com/leixuan111/p/10447328.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值