//@Override public Image process(Image imageIn) { int width = imageIn.getWidth(); int height = imageIn.getHeight(); double d = this.OriginAngleDegree * 0.0174532925; float cos = (float)Math.Cos(d); float sin = (float)Math.Sin(d); float radio = (cos * width) + (sin * height); float dcos = cos * radio; float dsin = sin * radio; int dist = (int)Math.Sqrt((double)((dcos * dcos) + (dsin * dsin))); dist = Math.Max(Math.Max(dist, width), height); if ((this.palette == null) || (dist != this.palette.Length)) { this.palette = this.Gradientf.CreatePalette(dist); } byte[] red = this.palette.Red; byte[] green = this.palette.Green; byte[] blue = this.palette.Blue; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { radio = (cos * j) + (sin * i); dcos = cos * radio; dsin = sin * radio; dist = (int)Math.Sqrt((double)((dcos * dcos) + (dsin * dsin))); imageIn.setPixelColor(j, i, red[dist], green[dist], blue[dist]); } } return imageIn; }
private Palette CreateGradient(List<Color> colors, int length) { if (colors == null || colors.Count < 2) { return null; } Palette palette = new Palette(length); byte[] red = palette.Red; byte[] green = palette.Green; byte[] blue = palette.Blue; int num = length / (colors.Count - 1); float num1 = 1f / ((float)num); int index = 0; Color rgb = colors[0]; int colorR = rgb.R; int colorG = rgb.G; int colorB = rgb.B; for (int i = 1; i < colors.Count; i++) { int r = colors[i].R; int g = colors[i].G; int b = colors[i].B; for (int j = 0; j < num; j++) { float num2 = j * num1; int rr = colorR + ((int)((r - colorR) * num2)); int gg = colorG + ((int)((g - colorG) * num2)); int bb = colorB + ((int)((b - colorB) * num2)); red[index] = (byte)(rr > 0xff ? 0xff : ((rr < 0) ? 0 : rr)); green[index] = (byte)(gg > 0xff ? 0xff : ((gg < 0) ? 0 : gg)); blue[index] = (byte)(bb > 0xff ? 0xff : ((bb < 0) ? 0 : bb)); index++; } colorR = r; colorG = g; colorB = b; } if (index < length) { red[index] = red[index - 1]; green[index] = green[index - 1]; blue[index] = blue[index - 1]; } return palette; }
public void ClearCache() { this.palette = null; }