请原谅,我的表述可能不是那么清楚。我详细一点说:
在我的程序中需要对图片进行调节对比度,亮度的操作,为了加快速度,我用BitBlt方法
在一个模块中定义一个函数
Public Function Brightness(ByVal DstDC As Long, ByVal DstBmp As Long, ByVal SrcDC As Long, ByVal SrcBmp As Long, ByVal TransColor As Long, ByVal Brightness As Long, Optional ByVal Flags As Long) As Long
Dim BitCount As Long
Dim retVal As Long
Dim Info As BITMAPINFO
Dim Width As Long, Height As Long
Dim TransR As Byte, TransG As Byte, TransB As Byte
Dim LineWidth As Long
Dim Bits() As Byte
Dim i As Long, b As Long, h As Long, D As Long
TransR = TransColor And &HFF
TransG = (TransColor And &HFF00&) / 255
TransB = (TransColor And &HFF0000) / 65536
Info.bmiHeader.biSize = Len(Info.bmiHeader)
retVal = GetDIBits(SrcDC, SrcBmp, 0, 0, ByVal 0, Info, 0)
If retVal = 0 Then Exit Function
Width = Info.bmiHeader.biWidth
Height = Info.bmiHeader.biHeight
Info.bmiHeader.biBitCount = 24
Info.bmiHeader.biCompression = 0
LineWidth = Width * 3
If (LineWidth Mod 4) Then LineWidth = LineWidth + 4 - (LineWidth Mod 4)
BitCount = LineWidth * Height
ReDim Bits(BitCount - 1)
retVal = GetDIBits(SrcDC, SrcBmp, 0, Height, Bits(0), Info, 0)
If retVal Then
If Brightness < -255 Then Brightness = -255
If Brightness > 255 Then Brightness = 255
i = 0
For h = 0 To Height - 1: For b = 0 To Width - 1
i = h * LineWidth + 3 * b
If (Flags And &H1) And (Bits(i + 2) = TransR) And (Bits(i + 1) = TransG) And (Bits(i) = TransB) Then
Else
If Brightness < 0 Then
For D = 0 To 2: Bits(i + D) = Bits(i + D) * (255 + Brightness) / 255: Next D
ElseIf Brightness > 0 Then
For D = 0 To 2: Bits(i + D) = 255 - (255 - Bits(i + D)) * (255 - Brightness) / 255: Next D
End If
End If
Next b: Next h SetDIBits DstDC, DstBmp, 0, Height, Bits(0), Info, 0
Erase Bits
End If
End Function其它的调节对比度的函数和这个类似,只有循环中的处理方法不一样。就不多贴了。
通过下面的事件调用函数:
Private Sub HScroll1_Change()
'这个滚动条控制图像的亮度
Label4.Caption = "阈值" & HScroll1.Value Brightness form_selected_bitmap.Picture1.hdc, form_selected_bitmap.Picture1.Image.Handle, form_selected_bitmap.Picture1.hdc, form_selected_bitmap.Picture1.Picture.Handle, 0, HScroll1, 0
form_selected_bitmap.Picture1.Refresh
End Sub然后当我另外一个ScrollBar调节亮度的时候,图片又回复成原样然后再调节亮度。
我的想法是:在调节了对比度以后,我在调节亮度应该是在调节了对比度的基础上调节亮度的。我的程序之所以要回复原样再调节,我想应该是缺少一个“写入”的过程。不知道我的理解正确不?
怎样解决,还请各位大侠多指教!
不甚感激!
在我的程序中需要对图片进行调节对比度,亮度的操作,为了加快速度,我用BitBlt方法
在一个模块中定义一个函数
Public Function Brightness(ByVal DstDC As Long, ByVal DstBmp As Long, ByVal SrcDC As Long, ByVal SrcBmp As Long, ByVal TransColor As Long, ByVal Brightness As Long, Optional ByVal Flags As Long) As Long
Dim BitCount As Long
Dim retVal As Long
Dim Info As BITMAPINFO
Dim Width As Long, Height As Long
Dim TransR As Byte, TransG As Byte, TransB As Byte
Dim LineWidth As Long
Dim Bits() As Byte
Dim i As Long, b As Long, h As Long, D As Long
TransR = TransColor And &HFF
TransG = (TransColor And &HFF00&) / 255
TransB = (TransColor And &HFF0000) / 65536
Info.bmiHeader.biSize = Len(Info.bmiHeader)
retVal = GetDIBits(SrcDC, SrcBmp, 0, 0, ByVal 0, Info, 0)
If retVal = 0 Then Exit Function
Width = Info.bmiHeader.biWidth
Height = Info.bmiHeader.biHeight
Info.bmiHeader.biBitCount = 24
Info.bmiHeader.biCompression = 0
LineWidth = Width * 3
If (LineWidth Mod 4) Then LineWidth = LineWidth + 4 - (LineWidth Mod 4)
BitCount = LineWidth * Height
ReDim Bits(BitCount - 1)
retVal = GetDIBits(SrcDC, SrcBmp, 0, Height, Bits(0), Info, 0)
If retVal Then
If Brightness < -255 Then Brightness = -255
If Brightness > 255 Then Brightness = 255
i = 0
For h = 0 To Height - 1: For b = 0 To Width - 1
i = h * LineWidth + 3 * b
If (Flags And &H1) And (Bits(i + 2) = TransR) And (Bits(i + 1) = TransG) And (Bits(i) = TransB) Then
Else
If Brightness < 0 Then
For D = 0 To 2: Bits(i + D) = Bits(i + D) * (255 + Brightness) / 255: Next D
ElseIf Brightness > 0 Then
For D = 0 To 2: Bits(i + D) = 255 - (255 - Bits(i + D)) * (255 - Brightness) / 255: Next D
End If
End If
Next b: Next h SetDIBits DstDC, DstBmp, 0, Height, Bits(0), Info, 0
Erase Bits
End If
End Function其它的调节对比度的函数和这个类似,只有循环中的处理方法不一样。就不多贴了。
通过下面的事件调用函数:
Private Sub HScroll1_Change()
'这个滚动条控制图像的亮度
Label4.Caption = "阈值" & HScroll1.Value Brightness form_selected_bitmap.Picture1.hdc, form_selected_bitmap.Picture1.Image.Handle, form_selected_bitmap.Picture1.hdc, form_selected_bitmap.Picture1.Picture.Handle, 0, HScroll1, 0
form_selected_bitmap.Picture1.Refresh
End Sub然后当我另外一个ScrollBar调节亮度的时候,图片又回复成原样然后再调节亮度。
我的想法是:在调节了对比度以后,我在调节亮度应该是在调节了对比度的基础上调节亮度的。我的程序之所以要回复原样再调节,我想应该是缺少一个“写入”的过程。不知道我的理解正确不?
怎样解决,还请各位大侠多指教!
不甚感激!
您能说详细一点吗?或者给一个例程的链接?谢谢!