Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.
  2.  
  3. Color blend = Color.White;
  4. Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.
  5. Color rgb = ToRGB(argb, blend); //Same as Color.FromARGB(255, 162, 133, 255);
  6.  
  7. alpha=argb.alpha()r = (alpha/255)*argb.r() + (1 - alpha/255)*blend.r()g = (alpha/255)*argb.g() + (1 - alpha/255)*blend.g()b = (alpha/255)*argb.b() + (1 - alpha/255)*blend.b()
  8.  
  9. Public Shared Function AlphaBlend(ByVal ForeGround As Color, ByVal BackGround As Color) As Color
  10. If ForeGround.A = 0 Then Return BackGround
  11. If BackGround.A = 0 Then Return ForeGround
  12. If ForeGround.A = 255 Then Return ForeGround
  13. Dim Alpha As Integer = CInt(ForeGround.A) + 1
  14. Dim B As Integer = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8
  15. Dim G As Integer = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8
  16. Dim R As Integer = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8
  17. Dim A As Integer = ForeGround.A
  18.  
  19. If BackGround.A = 255 Then A = 255
  20. If A > 255 Then A = 255
  21. If R > 255 Then R = 255
  22. If G > 255 Then G = 255
  23. If B > 255 Then B = 255
  24.  
  25. Return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B))
  26. End Function
  27.  
  28. public static Color AlphaBlend(Color ForeGround, Color BackGround)
  29. {
  30. if (ForeGround.A == 0)
  31. return BackGround;
  32. if (BackGround.A == 0)
  33. return ForeGround;
  34. if (ForeGround.A == 255)
  35. return ForeGround;
  36.  
  37. int Alpha = Convert.ToInt32(ForeGround.A) + 1;
  38. int B = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8;
  39. int G = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8;
  40. int R = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8;
  41. int A = ForeGround.A;
  42.  
  43. if (BackGround.A == 255)
  44. A = 255;
  45. if (A > 255)
  46. A = 255;
  47. if (R > 255)
  48. R = 255;
  49. if (G > 255)
  50. G = 255;
  51. if (B > 255)
  52. B = 255;
  53.  
  54. return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B));
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement