Victor Image Processing Library How-to Tips

Convert a JPEG Image to a BMP

Converting from one image file format to another is easy with Victor. Determine the size of the image and allocate space for it in memory, load the JPEG, and save the BMP.

In general, to convert from one image format to another, the steps are:

VB Source Code | C Source Code

JPEG to BMP - the Visual Basic Source Code

Requires Victor Image Processing Library for 32-bit Windows v 5 or higher.
Private Sub mnuconvertJPGtoBMP_Click()
   Dim tmpimage As imgdes
   Dim rcode As Long
   Dim jdat As JpegData     ' Reserve space for JPEG file info
   Dim bmp_fname As String
   Dim jpg_fname As String
   bmp_fname = "test.bmp"
   jpg_fname = "test.jpg"
            ' Get info on the file we're to load
   rcode = jpeginfo(jpg_fname, jdat)
   If (rcode <> NO_ERROR) Then
      MsgBox "Cannot find file", 0, "Error encountered!"
      Exit Sub
   End If
            ' Allocate space for an image
   rcode = allocimage(tmpimage, jdat.width, jdat.length, jdat.vbitcount)
   If (rcode <> NO_ERROR) Then
     MsgBox "Not enough memory", 0, "Error encountered!"
     Exit Sub
   End If
            ' Load image
   rcode = loadjpg(jpg_fname, tmpimage)
   If (rcode <> NO_ERROR) Then
      freeimage tmpimage ' Free image on error
      MsgBox "Cannot load file", 0, "Error encountered!"
      Exit Sub
   End If
            ' Save image
   rcode = savebmp(bmp_fname, tmpimage, 0)
   freeimage tmpimage
End Sub
........... Add these defines and declarations to your Global module ...........
' Image descriptor
Type imgdes
   ibuff As Long
   stx As Long
   sty As Long
   endx As Long
   endy As Long
   buffwidth As Long
   palette As Long
   colors As Long
   imgtype As Long
   bmh As Long
   hBitmap As Long
End Type
Type JpegData
    ftype As Long
    width As Long
    length As Long
    comps As Long
    precision As Long
    sampfac0 As Long
    sampfac1 As Long
    sampfac2 As Long
    sampfac3 As Long
    vbitcount As Long
End Type
Declare Function jpeginfo Lib "VIC32.DLL" (ByVal Fname As String, jdat As JpegData) As Long
Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal BPPixel As Long) As Long
Declare Function loadjpg Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes) As Long
Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Declare Function savebmp Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes, ByVal compression As Long) As Long

JPEG to BMP - the Source Code

Requires Victor Image Processing Library v 4.1x or higher.
int jpeg2bmp(char far *src_fname, char far *des_fname)
   imgdes tmpimage;
   JpegData jdat;
   int rcode, comp=0;
            // Get info on the file we're to load 
   rcode = jpeginfo(src_fname, &jdat);
   if(rcode != NO_ERROR) {
            // Allocate space for an image
   rcode = allocimage(&tmpimage, (int)jdat.width, (int)jdat.length, jdat.vbitcount);
   if(rcode != NO_ERROR) {
            // Load image 
   rcode = loadjpg(src_fname, &tmpimage);
   if(rcode != NO_ERROR) { 
      freeimage(&tmpimage); // Free image on error
            // Save image
   rcode = savebmp(des_fname, &tmpimage, comp);
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code

Copyright © 1995 - 2000 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.