public void DrawLine(int x1, int y1, int x2, int y2, Argb32 color) { if (y1 == y2) { this.DrawHorizontalLine(x1, y1, x2, color); return; } if (x1 == x2) { this.DrawVerticalLine(x1, y1, y2, color); return; } int dx = Math.Abs(x2 - x1), sx = x1 < x2 ? 1 : -1; int dy = Math.Abs(y2 - y1), sy = y1 < y2 ? 1 : -1; int err = (dx > dy ? dx : -dy) / 2, e2; while (true) { this.SetPixel(x1, y1, color); if (x1 == x2 && y1 == y2) { break; } e2 = err; if (e2 > -dx) { err -= dy; x1 += sx; } if (e2 < dy) { err += dx; y1 += sy; } } }
public void AlphaBlend(Argb32 foreGround, double opacity) { if (foreGround.A == 255 && opacity == 1) { this.A = foreGround.A; this.R = foreGround.R; this.G = foreGround.G; this.B = foreGround.B; this.Color = foreGround.Color; return; } if (foreGround.A == 0) { return; } var colora = this.color; var colorb = foreGround.color; uint a2 = foreGround.A; //(colorb & 0xFF000000) >> 24; // prendre en compte l'opacité globale a2 = (uint)((double)a2 * opacity); uint a1 = (colora & 0xFF000000) >> 24; uint nalpha = 0x100 - a2; uint rb1 = (nalpha * (colora & 0xFF00FF)) >> 8; uint rb2 = (a2 * (colorb & 0xFF00FF)) >> 8; uint g1 = (nalpha * (colora & 0x00FF00)) >> 8; uint g2 = (a2 * (colorb & 0x00FF00)) >> 8; uint anew = a1 + a2; if (anew > 255) { anew = 255; } this.SetColor(((rb1 + rb2) & 0xFF00FF) + ((g1 + g2) & 0x00FF00) + (anew << 24)); //if (foreGround.A == 0) // return; //if (this.A == 0) //{ // this.SetColor(foreGround); // return; //} //foreGround.A = (byte)((double)foreGround.A * opacity); //if (foreGround.A == 255) //{ // this.SetColor(foreGround); // return; //} //int Alpha = ((int)foreGround.A) + 1; //int B = Alpha * foreGround.B + (255 - Alpha) * this.B >> 8; //int G = Alpha * foreGround.G + (255 - Alpha) * this.G >> 8; //int R = Alpha * foreGround.R + (255 - Alpha) * this.R >> 8; //int A = foreGround.A; //if (this.A == 255) // A = 255; //if (A > 255) // A = 255; //if (R > 255) // R = 255; //if (G > 255) // G = 255; //if (B > 255) // B = 255; //this.SetColor((byte)Math.Abs(A), (byte)Math.Abs(R), (byte)Math.Abs(G), (byte)Math.Abs(B)); }
public void SetColor(Argb32 color) { SetColor(color.a, color.r, color.g, color.b); }