In general, to convert from one image format to another, the steps are:
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
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) {
return(rcode);
}
// Allocate space for an image
rcode = allocimage(&tmpimage, (int)jdat.width, (int)jdat.length, jdat.vbitcount);
if(rcode != NO_ERROR) {
return(rcode);
}
// Load image
rcode = loadjpg(src_fname, &tmpimage);
if(rcode != NO_ERROR) {
freeimage(&tmpimage); // Free image on error
return(rcode);
}
// Save image
rcode = savebmp(des_fname, &tmpimage, comp);
freeimage(&tmpimage);
return(rcode);
}
Victor Image Processing Library homepage | Victor Product Summary | more source code