颜色转byte数组的算法
byte[] ColorToByte(Color[] colors, int w, int h, float scale)
{
var neww = (int)(w * scale);
var newh = (int)(h * scale);
var offset = 1 / scale;
byte[] newdata = new byte[newh * neww * 3 ];
var ci = 0;
for (var j = 0; j < newh; j ++)//= offset)
{
for (var i = 0; i < neww; i ++)//= offset)
{
ci = 3*(i + j * neww);
var color = colors[(int)(i*offset) + (int)(j *offset)*w];
newdata[ci+0] = (byte)(color.r * 255);
newdata[ci+1] = (byte)(color.g * 255);
newdata[ci+2] = (byte)(color.b * 255);
}
}
return newdata;
}
挺有用的,在这里记录一下。