Public Function LoadJPG(ByRef cDib As cDIBSection, ByVal sFile As String) As Boolean Dim tJ As JPEG_CORE_PROPERTIES_VB Dim bFile() As Byte Dim lR As Long Dim lPtr As Long Dim lJPGWidth As Long, lJPGHeight As Long lR = ijlInit(tJ) If lR = IJL_OK Then
' Write the filename to the jcprops.JPGFile member: bFile = StrConv(sFile, vbFromUnicode) ReDim Preserve bFile(0 To UBound(bFile) + 1) As Byte bFile(UBound(bFile)) = 0 lPtr = VarPtr(bFile(0)) CopyMemory tJ.JPGFile, lPtr, 4
' Read the JPEG file parameters: lR = ijlRead(tJ, IJL_JFILE_READPARAMS) If lR <> IJL_OK Then ' Throw error MsgBox "Failed to read JPG", vbExclamation Else
' Get the JPGWidth ... lJPGWidth = tJ.JPGWidth ' .. & JPGHeight member values: lJPGHeight = tJ.JPGHeight
' Create a buffer of sufficient size to hold the image: If cDib.Create(lJPGWidth, lJPGHeight) Then ' Store DIBWidth: tJ.DIBWidth = lJPGWidth ' Store DIBHeight: tJ.DIBHeight = -lJPGHeight ' Store Channels: tJ.DIBChannels = 3& ' Store DIBBytes (pointer to uncompressed JPG data): tJ.DIBBytes = cDib.DIBSectionBitsPtr
' Now decompress the JPG into the DIBSection: lR = ijlRead(tJ, IJL_JFILE_READWHOLEIMAGE) If lR = IJL_OK Then ' That's it! cDib now contains the uncompressed JPG. LoadJPG = True Else ' Throw error: MsgBox "Cannot read Image Data from file.", vbExclamation End If Else ' failed to create the DIB... End If End If
' Ensure we have freed memory: ijlFree tJ Else ' Throw error: MsgBox "Failed to initialise the IJL library: " & lR, vbExclamation End If
End Function Public Function SaveJPG(ByRef cDib As cDIBSection, ByVal sFile As String) As Boolean Dim tJ As JPEG_CORE_PROPERTIES_VB Dim bFile() As Byte Dim lPtr As Long Dim lR As Long
lR = ijlInit(tJ) If lR = IJL_OK Then ' Set up the DIB information: ' Store DIBWidth: tJ.DIBWidth = cDib.Width ' Store DIBHeight: tJ.DIBHeight = -cDib.Height ' Store DIBBytes (pointer to uncompressed JPG data): tJ.DIBBytes = cDib.DIBSectionBitsPtr
' Set up the JPEG information:
' Store JPGFile: bFile = StrConv(sFile, vbFromUnicode) ReDim Preserve bFile(0 To UBound(bFile) + 1) As Byte bFile(UBound(bFile)) = 0 lPtr = VarPtr(bFile(0)) CopyMemory tJ.JPGFile, lPtr, 4 ' Store JPGWidth: tJ.JPGWidth = cDib.Width ' .. & JPGHeight member values: tJ.JPGHeight = cDib.Height
tJ.jquality = 90
' Write the image: lR = ijlWrite(tJ, IJL_JFILE_WRITEWHOLEIMAGE) If lR = IJL_OK Then SaveJPG = True Else ' Throw error MsgBox "Failed to save to JPG", vbExclamation End If
' Ensure we have freed memory: ijlFree tJ Else ' Throw error: MsgBox "Failed to initialise the IJL library: " & lR, vbExclamation End If End Function
Dim tJ As JPEG_CORE_PROPERTIES_VB
Dim bFile() As Byte
Dim lR As Long
Dim lPtr As Long
Dim lJPGWidth As Long, lJPGHeight As Long lR = ijlInit(tJ)
If lR = IJL_OK Then
' Write the filename to the jcprops.JPGFile member:
bFile = StrConv(sFile, vbFromUnicode)
ReDim Preserve bFile(0 To UBound(bFile) + 1) As Byte
bFile(UBound(bFile)) = 0
lPtr = VarPtr(bFile(0))
CopyMemory tJ.JPGFile, lPtr, 4
' Read the JPEG file parameters:
lR = ijlRead(tJ, IJL_JFILE_READPARAMS)
If lR <> IJL_OK Then
' Throw error
MsgBox "Failed to read JPG", vbExclamation
Else
' Get the JPGWidth ...
lJPGWidth = tJ.JPGWidth
' .. & JPGHeight member values:
lJPGHeight = tJ.JPGHeight
' Create a buffer of sufficient size to hold the image:
If cDib.Create(lJPGWidth, lJPGHeight) Then
' Store DIBWidth:
tJ.DIBWidth = lJPGWidth
' Store DIBHeight:
tJ.DIBHeight = -lJPGHeight
' Store Channels:
tJ.DIBChannels = 3&
' Store DIBBytes (pointer to uncompressed JPG data):
tJ.DIBBytes = cDib.DIBSectionBitsPtr
' Now decompress the JPG into the DIBSection:
lR = ijlRead(tJ, IJL_JFILE_READWHOLEIMAGE)
If lR = IJL_OK Then
' That's it! cDib now contains the uncompressed JPG.
LoadJPG = True
Else
' Throw error:
MsgBox "Cannot read Image Data from file.", vbExclamation
End If
Else
' failed to create the DIB...
End If
End If
' Ensure we have freed memory:
ijlFree tJ
Else
' Throw error:
MsgBox "Failed to initialise the IJL library: " & lR, vbExclamation
End If
End Function
Public Function SaveJPG(ByRef cDib As cDIBSection, ByVal sFile As String) As Boolean
Dim tJ As JPEG_CORE_PROPERTIES_VB
Dim bFile() As Byte
Dim lPtr As Long
Dim lR As Long
lR = ijlInit(tJ)
If lR = IJL_OK Then
' Set up the DIB information:
' Store DIBWidth:
tJ.DIBWidth = cDib.Width
' Store DIBHeight:
tJ.DIBHeight = -cDib.Height
' Store DIBBytes (pointer to uncompressed JPG data):
tJ.DIBBytes = cDib.DIBSectionBitsPtr
' Set up the JPEG information:
' Store JPGFile:
bFile = StrConv(sFile, vbFromUnicode)
ReDim Preserve bFile(0 To UBound(bFile) + 1) As Byte
bFile(UBound(bFile)) = 0
lPtr = VarPtr(bFile(0))
CopyMemory tJ.JPGFile, lPtr, 4
' Store JPGWidth:
tJ.JPGWidth = cDib.Width
' .. & JPGHeight member values:
tJ.JPGHeight = cDib.Height
tJ.jquality = 90
' Write the image:
lR = ijlWrite(tJ, IJL_JFILE_WRITEWHOLEIMAGE)
If lR = IJL_OK Then
SaveJPG = True
Else
' Throw error
MsgBox "Failed to save to JPG", vbExclamation
End If
' Ensure we have freed memory:
ijlFree tJ
Else
' Throw error:
MsgBox "Failed to initialise the IJL library: " & lR, vbExclamation
End If
End Function
我怎么用SaveJPG保存
http://www.fantasiasoft.net/bmp2jpeg.zip
http://www.fantasiasoft.net/jpegread.zip