private byte[] GetSmallImageData(Argb32DataWithSize source, int width, int height) { // 等間隔にサンプリングして平均をとる byte[] result = new byte[width * height * 4]; int s = 12; // s*s = サンプリング数 int pos = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int srcX0 = x * source.Width / width; int srcY0 = y * source.Height / height; int r = 0; int g = 0; int b = 0; int a = 0; // 縮小した画素に対して縮小元から s * s 画素を取得し // 平均値を計算 for (int yy = 0; yy < s; yy++) { for (int xx = 0; xx < s; xx++) { int dx = xx * source.Width / width / s; int dy = yy * source.Height / height / s; int p = ((srcX0 + dx) + (srcY0 + dy) * source.Width) * 4; b += source.Payload[p]; g += source.Payload[p + 1]; r += source.Payload[p + 2]; a += source.Payload[p + 3]; } } result[pos++] = (byte)(b / s / s); result[pos++] = (byte)(g / s / s); result[pos++] = (byte)(r / s / s); result[pos++] = (byte)(a / s / s); } } return(result); }
private byte[] GetSmallImageData(Argb32DataWithSize source, int width, int height) { // 等間隔にサンプリングして平均をとる byte[] result = new byte[width * height * 4]; int s = 12; // s*s = サンプリング数 int pos = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int srcX0 = x * source.Width / width; int srcY0 = y * source.Height / height; int r = 0; int g = 0; int b = 0; int a = 0; // 縮小した画素に対して縮小元から s * s 画素を取得し // 平均値を計算 for (int yy = 0; yy < s; yy++) { for (int xx = 0; xx < s; xx++) { int dx = xx * source.Width / width / s; int dy = yy * source.Height / height / s; int p = ((srcX0 + dx) + (srcY0 + dy) * source.Width) * 4; b += source.Payload[p]; g += source.Payload[p + 1]; r += source.Payload[p + 2]; a += source.Payload[p + 3]; } } result[pos++] = (byte)(b / s / s); result[pos++] = (byte)(g / s / s); result[pos++] = (byte)(r / s / s); result[pos++] = (byte)(a / s / s); } } return result; }