Home > Software engineering >  Adjust the image color, display pictures color distortion, looking forward to solve.
Adjust the image color, display pictures color distortion, looking forward to solve.

Time:10-04

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function VarPtrArray Lib "msvbvm60. DLL" Alias "VarPtr" (Ptr () As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pSrc pDest As Any, As Any, ByVal ByteLen As Long)

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal HDC) As Long As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal HDC) As Long As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal HDC As Long, ByVal hObject As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal HDC, As Long As pBitmapInfo BITMAPINFOHEADER, ByVal UN As Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Declare Function SetDIBits Lib "gdi32" (ByVal HDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal HDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long

Private Type BITMAPINFOHEADER 'of the BITMAP file header structure
BiSize As Long
BiWidth As Long
BiHeight As Long
BiPlanes As Integer
BiBitCount As Integer
BiCompression As Long
BiSizeImage As Long
BiXPelsPerMeter As Long
BiYPelsPerMeter As Long
BiClrUsed As Long
BiClrImportant As Long
End Type

Private Type BITMAPINFO
BmiHeader As BITMAPINFOHEADER
BmiColors As RGBQUAD
End Type

Private Type BITMAP
BmType As Long
BmWidth As Long
BmHeight As Long
BmWidthBytes As Long
BmPlanes As Integer
BmBitsPixel As Integer
BmBits As Long
End Type

Private Type RGB_DATA
'As A Byte
B As Byte
G As Byte
R As Byte
End Type


Sub AdjustHSL (pSrc As PictureBox pDes As PictureBox, Hue As Long, Saturation As Long, _
Optional srcX As Long, _
Optional srcY As Long, _
Optional SrcW As Long, _
Optional SrcH As Long)
'On the Error Resume Next
Dim R As Byte, G, B As Byte, As Byte As A Byte, H As Single, S As Single, L As Single
Dim dH As Long, dS, As Long As Long X, Y As Long

Dim MyhDC As Long
Dim MyBMIH As BITMAPINFOHEADER
Dim MyhDIB As Long
Dim MyPtr As Long
Dim hOldMap As Long
Dim MapData () As Byte
Dim MaxI As Long
Dim IRGB () As RGB_DATA
Dim ISize As Long
Dim bi As BITMAPINFO

If SrcW=0 Then SrcW=pSrc. ScaleWidth
If SrcH=0 Then SrcH=pSrc. ScaleHeight

With MyBMIH
. BiSize=40
. BiWidth=SrcW
. BiHeight=SrcH
. The biPlanes=1
. BiBitCount=24
The biSizeImage=(. BiWidth * (. BiBitCount/8)) *. BiHeight
End With
Bi. BmiHeader=MyBMIH
ISize=MyBMIH. BiSizeImage
MyhDC=CreateCompatibleDC (0)
MyhDIB=CreateDIBSection (MyPtr MyhDC, MyBMIH, 0, 0, 0)
'the Debug. Print "MyhDIB="; MyhDIB
If MyhDIB=0 Then DeleteObject MyhDC: Exit Sub

HOldMap=SelectObject (MyhDC MyhDIB)
BitBlt MyhDC, 0, 0, SrcW, SrcH, pSrc. HDC, srcX, srcY, vbSrcCopy
ReDim IRGB (0 To SrcW - 1, 0) To SrcH - 1
Call GetBitmapBits (MyhDIB, ISize IRGB (0, 0))
'GetDIBits MyhDC MyhDIB, 0, SrcH, IRGB (0, 0), bi, 0

For Y=0 To SrcH - 1
For X=0 To SrcW - 1
RGBtoHSL IRGB (X, Y). R, IRGB (X, Y). G, IRGB (X, Y). B, H, S, L
DH=H + Hue/30
If dH & lt; 1 Then dH dH + 6=Else If dH & gt; 5 Then dH=dH - 6
S=S + Saturation/100
If the S & gt; 1 Then S=1 Else If S & lt; 0 Then S=0
HSLtoRGB dH, S, L, IRGB (X, Y). R, IRGB (X, Y). G, IRGB (X, Y).
BNext X
Next Y

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related