1、VB实现图片格式转换BMP转JPGOption Explicit Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(0 To 7) As Byte End Type Private Type GdiplusStartupInput GdiplusVersion As Long DebugEventCallback As Long SuppressBackgroundThread As Long SuppressExternalC
2、odecs As Long End Type Private Type EncoderParameter GUID As GUID NumberOfValues As Long type As Long Value As Long End Type Private Type EncoderParameters Count As Long Parameter As EncoderParameter End Type Private Declare Function GdiplusStartup Lib "GDIPlus" (t
3、oken As Long, inputbuf As GdiplusStartupInput, ByVal outputbuf As Long) As Long Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hpal As Long,
4、 Bitmap As Long) As Long Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long Private Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal filename As Long, clsidEncoder As GUID, encoderParams As Any) As Long Pri
5、vate Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal filename As Long, Bitmap As Long) As Long Private Sub Command1_Click() Dim ret As Boolean Picture1.Picture
6、= LoadPicture("C:a.bmp") '打开要压缩的图片 ret = PictureBoxSaveJPG(Picture1, "C:b.jpg") '保存压缩后的图片 If ret = False Then MsgBox "保存失败" End If End Sub Private Function PictureBoxSaveJPG(ByVal pict As StdPicture, ByVal filename As String, Optional ByVal quality As Byte = 80) A
7、s Boolean Dim tSI As GdiplusStartupInput Dim lRes As Long Dim lGDIP As Long Dim lBitmap As Long '初始化 GDI+ tSI.GdiplusVersion = 1 lRes = GdiplusStartup(lGDIP, tSI, 0) If lRes = 0 Then '从句柄创建 GDI+ 图像 lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)
8、 If lRes = 0 Then Dim tJpgEncoder As GUID Dim tParams As EncoderParameters '初始化解码器的GUID标识 CLSIDFro