Public Shared Function ChangeContrast(ByVal img As Image, ByVal contrast As Single) As Image Dim newImg As New Bitmap(img.Width, img.Height) Dim g As Graphics = Graphics.FromImage(newImg) Dim scale As Single = (100.0F + contrast) / 100.0F scale *= scale Dim append As Single = 0.5F * (1.0F - scale) Dim cm As New System.Drawing.Imaging.ColorMatrix(New Single()() { New Single() {scale, 0, 0, 0, 0}, New Single() {0, scale, 0, 0, 0}, New Single() {0, 0, scale, 0, 0}, New Single() {0, 0, 0, 1, 0}, New Single() {append, append, append, 0, 1}}) Dim ia As New System.Drawing.Imaging.ImageAttributes() ia.SetColorMatrix(cm) g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia) g.Dispose() Return newImg End Function Private Sub NumericUpDown5_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown5.ValueChanged TrackBar5.Value = NumericUpDown5.Value End Sub Private Sub TrackBar5_Scroll(sender As Object, e As EventArgs) Handles TrackBar5.Scroll Dim ChangeSaturationImg As New Bitmap(PictureBox1.Image) Dim newImg As Image = ChangeSaturation(ChangeSaturationImg, Decimal.ToSingle(TrackBar5.Value)) ChangeSaturationImg.Dispose() If Not PictureBox2.Image Is Nothing Then PictureBox2.Image.Dispose() End If PictureBox2.Image = newImg NumericUpDown5.Value = TrackBar5.Value End Sub
失礼致しました。ColorMatrix入りのコードはこちらです。間違った物をコピペした様です。申し訳ありませんが、宜しく絵願いします。 Public Shared Function ChangeSaturation(ByVal img As Image, ByVal saturation As Single) As Image Dim newImg As New Bitmap(img.Width, img.Height) Dim g As Graphics = Graphics.FromImage(newImg) Dim cm As New Imaging.ColorMatrix() Const rwgt As Single = 0.3086F Const gwgt As Single = 0.6094F Const bwgt As Single = 0.082F cm.Matrix01 = (1.0F - saturation) * rwgt cm.Matrix02 = cm.Matrix01 cm.Matrix00 = cm.Matrix01 + saturation cm.Matrix10 = (1.0F - saturation) * gwgt cm.Matrix12 = cm.Matrix10 cm.Matrix11 = cm.Matrix10 + saturation cm.Matrix20 = (1.0F - saturation) * bwgt cm.Matrix21 = cm.Matrix20 cm.Matrix22 = cm.Matrix20 + saturation cm.Matrix33 = 1 cm.Matrix44 = 1 Dim ia As New Imaging.ImageAttributes() ia.SetColorMatrix(cm) g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia) g.Dispose() Return newImg End Function