StdPicture读取图片,BitBlt/StretchBlt API NOSRCCOPY 反色处理StdPicture图片,然后用SavePicture()方法保存图片就可以。 、 怎么个合并图像法?
直接使用PaintPicture即可,注意该函数的最后一个参数的使用。
visita + vb6 测试通过反色保存图片,支持VB所能支持的所有的图片格式Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source Private Const NOTSRCCOPY = &H330008 ' (DWORD) dest = (NOT source)Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) 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 LongPrivate Sub Command1_Click() ConvImage "c:\t1.jpg", "c:\t2.jpg" End SubPrivate Function ConvImage(ByVal strSrcImage As String, ByVal strDestImage As String) As Boolean Dim objPic As New StdPicture Dim lDC As Long, lMemDC As Long, lTmpDC As Long Dim lBitmap As Long, lBitmap1 As Long, lBitmap2 As Long Dim nHeight As Long, nWidth As Long
On Error GoTo Err_Conv
Set objPic = LoadPicture(strSrcImage) Debug.Assert objPic.Handle <> 0
、
怎么个合并图像法?
Private Const NOTSRCCOPY = &H330008 ' (DWORD) dest = (NOT source)Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) 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 LongPrivate Sub Command1_Click()
ConvImage "c:\t1.jpg", "c:\t2.jpg"
End SubPrivate Function ConvImage(ByVal strSrcImage As String, ByVal strDestImage As String) As Boolean
Dim objPic As New StdPicture
Dim lDC As Long, lMemDC As Long, lTmpDC As Long
Dim lBitmap As Long, lBitmap1 As Long, lBitmap2 As Long
Dim nHeight As Long, nWidth As Long
On Error GoTo Err_Conv
Set objPic = LoadPicture(strSrcImage)
Debug.Assert objPic.Handle <> 0
nWidth = ScaleX(objPic.Width, vbHimetric, vbPixels)
nHeight = ScaleY(objPic.Height, vbHimetric, vbPixels)
lDC = GetDC(0)
Debug.Assert lDC
lMemDC = CreateCompatibleDC(lDC)
lTmpDC = CreateCompatibleDC(lDC)
lBitmap = CreateCompatibleBitmap(lDC, nWidth, nHeight) ' 创建一个临时图片
Debug.Assert lBitmap And lMemDC And lTmpDC
lBitmap1 = SelectObject(lMemDC, objPic.Handle) ' 源图片
lBitmap2 = SelectObject(lTmpDC, lBitmap) ' 临时图片
StretchBlt lTmpDC, 0, 0, nWidth, nHeight, lMemDC, 0, 0, nWidth, nHeight, NOTSRCCOPY ' 反色绘图至临时图片
StretchBlt lMemDC, 0, 0, nWidth, nHeight, lTmpDC, 0, 0, nWidth, nHeight, SRCCOPY ' 将反色临时图片重新写回源图片
SelectObject lTmpDC, lBitmap2
SelectObject lMemDC, lBitmap1
SavePicture objPic, strDestImage ' 保存反色图片
DeleteObject lBitmap
DeleteDC lTmpDC
DeleteDC lMemDC
ReleaseDC 0, lDC ConvImage = True
Exit Function
Err_Conv:
MsgBox Err.Description
End Function