关于将BMP转换为JPG,谁用过ijl10.dll
我下了一个例程,但文件 不全
有谁知道ijl10.dll的函数及参数
cDIBSection 是怎么定义的?

解决方案 »

  1.   

    我也用过,ijl10.dll是将一个图片以RGBRGBRGB的方式输出到数组,然后你再设置到图片,不过我不知道怎么用那个DLL读取灰度图象
      

  2.   

    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
      

  3.   

    这个cDIBSection是怎么定义
    我怎么用SaveJPG保存
      

  4.   

    如果你不是要写特别大的Jpeg的话,用这个没什么意义(其实这个DLL我还没有研究透,但是你的代码有致命错误,我曾经修改过),你可以尝试用Delphi写的DLL
    http://www.fantasiasoft.net/bmp2jpeg.zip
      

  5.   

    我修改过的调用方法,上面的方法如果图象的Width是单数有读取错误(只有读取功能,而且还是有缺陷,无法读取灰度图象)
    http://www.fantasiasoft.net/jpegread.zip