VB.NET Programming
[VBNET] 이미지 밝기 조절(Image Brightness)
ZerosKD
2021. 5. 17. 13:02
반응형
* VBNET 이미지 밝기 조절 (Image Brightness) 예제...
- 사용한 컨트롤 : Button 3개, PictureBox 1개
전체 소스 코드
Form1.vb
Public Class Form1
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "JPG Files(*.jpg) | *.jpg"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
pictureBox1.Image = New Bitmap(ofd.FileName)
End If
End Sub
Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
'20 씩 밝기 증가
pictureBox1.Image = BrightnessImage(pictureBox1.Image, 20)
End Sub
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
'20 씩 밝기 감소
pictureBox1.Image = BrightnessImage(pictureBox1.Image, -20)
End Sub
Private Function BrightnessImage(ByVal imSource As Image, ByVal iBrightness As Integer) As Bitmap
Dim btTmp As Bitmap = New Bitmap(imSource)
Dim cTmp As Color
Dim iR As Integer, iG As Integer, iB As Integer
For iY As Integer = 0 To btTmp.Height - 1
For iX As Integer = 0 To btTmp.Width - 1
cTmp = btTmp.GetPixel(iX, iY)
iR = Math.Max(0, Math.Min(255, cTmp.R + iBrightness))
iG = Math.Max(0, Math.Min(255, cTmp.G + iBrightness))
iB = Math.Max(0, Math.Min(255, cTmp.B + iBrightness))
cTmp = Color.FromArgb(iR, iG, iB)
btTmp.SetPixel(iX, iY, cTmp)
Next
Next
Return btTmp
End Function
End Class
* 예제 결과
- 이미지 파일 열기...
- 밝기 조절 없이 기본 화면
- 밝기 100 정도 된 화면
- 밝기 -100 정도 된 화면
반응형