【发布时间】:2011-11-08 18:57:38
【问题描述】:
我正在使用 API 调用来转换位图对象。我有各种物理变换(旋转、翻转、缩放、位移)以及一些颜色调整(反转、亮度和对比度)
除了我将旋转或剪切变换与颜色调整结合使用时,一切正常。在这种情况下,颜色会恢复为原始图像。
这个问题的有趣之处在于它似乎依赖于 XForm 矩阵中的非对角线因子(下面的 eM12 和 eM21)。例如,这里是旋转矩阵:
Public Sub RotateClockwise(Radians As Single)
With XFormMatrix
.eM11 = Cos(Radians)
.eM12 = Sin(Radians)
.eM21 = -Sin(Radians)
.eM22 = Cos(Radians)
.eDx = 0
.eDy = 0
end with
end sub
只要 eM12 或 eM21 不为零,我的颜色就会消失!例如,剪切变换也会出现同样的问题:
Public Sub Shear(ShearFactorX As Single, ShearFactorY As Single)
With XFormMatrix
.eM11 = 1
.eM12 = ShearFactorX
.eM21 = ShearFactorY
.eM22 = 1
.eDx = 0
.eDy = 0
End With
End Sub
这是我应用变换并设置颜色调整的子(缩写)
Private Declare Function CreateCompatibleDC Lib "GDI32.dll" (ByVal hDC As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Declare Function SelectObject Lib "GDI32.dll" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function SetWorldTransform Lib "gdi32" (ByVal hDC As Long, ByRef lpXform As xForm) As Long
Private Declare Function SetColorAdjustment Lib "GDI32.dll" (ByVal hDC As Long, ByRef lpCA As ColorAdjustment) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Sub TransformAndDraw()
'Initialise objects
BufferDC = CreateCompatibleDC(0)
BgBuffer = CreateDIBSection(hDC:=BufferDC, pBitmapInfo:=bmi, un:=DIB_RGB_COLORS, lplpVoid:=0&, handle:=0&, dw:=0&)
SelectObject BufferDC, BgBuffer
'Define the transformation matrices
SetWorldTransform hDC:=BufferDC, lpXform:=XFormMatrix
' Apply this colour adustment to the Buffer DC
SetColorAdjustment hDC:=BufferDC, lpCA:=NewAdjust
'load picSource into the Buffer and apply scaling factor
StretchBlt hDC:=BufferDC, _
x:=0, _
y:=0, _
nWidth:=srcBmp.bmWidth * xsize, _
nHeight:=srcBmp.bmHeight * xsize, _
hSrcDC:=srcHDC, _
xSrc:=0, _
ySrc:=0, _
nSrcWidth:=srcBmp.bmWidth, _
nSrcHeight:=srcBmp.bmHeight, _
dwRop:=vbSrcCopy
'Paint the UserControl surface with the Buffer
'reset and delete objects
End Sub
总结一下我的问题:在我的非对角因子使用非零值时,有什么方法可以同时使用 SetWorldTransform 和 SetColorAdjustment XForm 转换?
【问题讨论】: