THE_LORD

Draw Image With Custom Color

Mar 10th, 2017
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.24 KB | None | 0 0
  1.     ''' <summary>
  2.     ''' <param name="G"> The Graphic to draw the image </param>
  3.     ''' <param name="R"> The Rectangle area of image </param>
  4.     ''' <param name="_Image"> The image that the custom color applies on it</param>
  5.     ''' <param name="C">The Color that be applied to the image </param>
  6.     ''' <remarks></remarks>
  7.     ''' </summary>
  8.     Public Sub DrawImageWithColor(ByVal G As Graphics, ByVal R As Rectangle, ByVal _Image As Image, C As Color)
  9.         Dim ptsArray As Single()() = {
  10.             New Single() {Convert.ToSingle(C.R / 255), 0, 0, 0, 0}, _
  11.             New Single() {0, Convert.ToSingle(C.G / 255), 0, 0, 0}, _
  12.             New Single() {0, 0, Convert.ToSingle(C.B / 255), 0, 0}, _
  13.             New Single() {0, 0, 0, Convert.ToSingle(C.A / 255), 0}, _
  14.             New Single() {Convert.ToSingle(C.R / 255), Convert.ToSingle(C.G / 255), Convert.ToSingle(C.B / 255), 0.0F, Convert.ToSingle(C.A / 255)}}
  15.         Dim imgAttribs As New Imaging.ImageAttributes
  16.         imgAttribs.SetColorMatrix(New Imaging.ColorMatrix(ptsArray), Imaging.ColorMatrixFlag.Default, Imaging.ColorAdjustType.Default)
  17.         G.DrawImage(_Image, R, 0, 0, _Image.Width, _Image.Height, GraphicsUnit.Pixel, imgAttribs)
  18.         _Image.Dispose()
  19.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment