1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
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 SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Const SRCCOPY = &HCC0020
Private Sub CmdLoad_Click()
On Error GoTo ErrorHandler
CD1.ShowOpen
PicBW.Picture = LoadPicture(CD1.FileName)
ErrorHandler:
End Sub
Private Sub CmdDither_Click()
PicBW.Cls
GradInt = (PicDither.Width / 15) / 11
For v = 0 To PicBW.Height / 15 - 1
For h = 0 To PicBW.Width / 15 - 1
CurRGB = (RGBCon(GetPixel(PicBW.hdc, h, v), 1) + RGBCon(GetPixel(PicBW.hdc, h, v), 2) + RGBCon(GetPixel(PicBW.hdc, h, v), 3)) / 3
PalLoc = 0
Do Until GradInt * PalLoc > (CurRGB / 255) * (PicDither.Width / 15)
PalLoc = PalLoc + 1
Loop
PalLoc = PalLoc - 2
Sclh = h
Sclv = v
If h > 15 Then Sclh = h Mod 16
If v > 15 Then Sclv = v Mod 16
SetPixel PicBW.hdc, h, v, GetPixel(PicDither.hdc, GradInt * PalLoc + Sclh, Sclv)
Next h
PicBW.Refresh
LblProg.Caption = Format(100 * (v + h / (PicBW.Width / 15 - 1)) / (PicBW.Height / 15 - 1), "0.00") & "%"
LblProg.Refresh
Next v
End Sub
Private Function RGBCon(RGBColor, CType As Integer)
'Convert RGB integer to R (CType = 1), G (CType = 2), or B (CType = 3) integer
If CType = 1 Then
CType = 3
ElseIf CType = 3 Then
CType = 1
End If
HRGB = Left("000000", 6 - Len(Hex(RGBColor))) & Hex(RGBColor)
RGBCon = Val("&H" & Mid(HRGB, 1 + 2 * (CType - 1), 2))
End Function
Private Sub CmdSave_Click()
SavePicture PicBW.Image, App.Path & "\Temp.bmp"
MsgBox "Saved to: " & App.Path & "\Temp.bmp", , "Saved"
End Sub |
Partager