Hi guys, I'm having problems converting .bmp to .jpg using vb6.
:icon_question:The idea is to convert .bmp to .jpg so i can import the saved image to a pdf file for email and/or printing.

I downloaded code that's supposed to convert .bmp to .jpg, but I get a compiler error saying I need to "specify user-type".

:)Any help would be appreciated.

---Here's the code---

Dim tmpimage As imagedes 'Image Descriptors
Dim tmp2image As imagedes
Dim rcode As Long
Dim quality As Long
Dim vbitcountcount As Long
Dim bdat As BITMAPINFOHEADER 'Reserve space for BMP struct
Dim bmp_fname As String
Dim jpg_fname As String

bmp_fname = "test.bmp"
jpg_fname = "test.jpg"

quality = 75
'get info on the file were going to load

rcode = bmpinfo(bmp_fname, bdat)
If (rcode <> NO_ERROR) Then
    MsgBox "Cannot find file", 0, "Error encountered!"
    Exit Sub
End If
''mr jelousy***************************
vbitcount = bdat.biBitCount
If (vbitcount >= 16) Then   '16-,24- or 32-bit image is
                            'loaded into 24-bit buffer
    vbitcount = 24
End If

'allocate space for an image
rcode = allocimage(tmpimage, bdat.biHeight, vbitcount)
If (rcode <> NO_ERROR) Then
    MsgBox "Not enough Memory", 0, "Error encountered!"
    Exit Sub
End If

'Load image
rcode = loadbmp(bmp_fname, tmpimage)
If (rcode <> NO_ERROR) Then
    freeimage tmpimage ' Free image on Error
    MsgBox "Cannot load file", 0, "Error encountered!"
    Exit Sub
End If

If (vbitcount = 1) Then 'If we loaded a 1-bit image
                        ',convert to 8-bit grayscale
                        'because jpeg only supports 8-bit
                        'grayscale or 24-bit color images
    rcode = allocimage(tmp2image, bdat.biHeight, 8)
    
    If (rcode = NO_ERROR) Then
        rcode = convert1bitto8bit(tmpimage, tmp2image)
        freeimage tmpimage  'replace 1-bit image with grayscale image
        copyimgdes tmp2image, tmpimage
    End If
End If

'save image
rcode = savejpg(jpg_fname, tmpimage, quality)
freeimage tmpimage

End Sub

:$I'm having problems understanding the code so even an explanation of the variables and functions would help alot.

This is the problem on using 3rd party controls.:)

Have a look at the following attachment, which is much easier to use. You do however need to register the control on your system first for it to work. Copy the ocx file, paste it in your system 32 folder. Use cmd, type regsvr32 jpeg32.ocx and then use the app. Have a look at the demo side on how it will work.

great code :)

App Wont work.
I get this message in the demo.txt file


Line 82: Class Jpeg32a.Jpeg32 of control Jpeg321 was not a loaded control class.
Line 85: The property name _ExtentX in Jpeg321 is invalid.
Line 86: The property name _ExtentY in Jpeg321 is invalid.

I've tried reinstalling vb6 and msdn libraries but still get the same problem.
Any idea why it wont run?:-/

Please read my post above first. You need to register the ocx control FIRST, otherwise it will not work.

You do however need to register the control on your system first for it to work. Copy the ocx file, paste it in your system 32 folder. Use cmd, type regsvr32 jpeg32.ocx and then use the app. Have a look at the demo side on how it will work.

Thanks JX.

I have registered the ocx control. I got a popup saying
"DllRegisterServer in jpeg32.ocx succeeded."
But the control still won't work.

Cool, now go to your toolbar at the top. Click on "project" "references. Select "jpg32" from the list and you will be ok.:)

I have registered jpeg32.ocx but still cant find the dll file jpeg32.dll. It is showing error "File not found: JPeg32.dll" on executing the line
BmpToJpeg BimapFilename, JpegFilename, CompressQuality

same here as arun 7

got to register the ocx with success, selected the component (not the reference bc it didnt appear in the list, only in component). So when i click on the convert button it says missing jpeg32.dll

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.