Solved

Convert bmp to jpg

Posted on 2003-12-03
5
24,803 Views
Last Modified: 2013-11-19
Anyone know or has a function who convert bmp to jpg (with low compression)
0
Comment
Question by:meciab
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Assisted Solution

by:mccainz2
mccainz2 earned 50 total points
ID: 9867660
0
 
LVL 2

Assisted Solution

by:bdbrown
bdbrown earned 50 total points
ID: 9867895
Try here!

This is the Intel® JPEG Library that is used to save and load JPG/JPEG files in Visual Basic.  This DLL does not need to be registered with REGSVR32.EXE.  See the following module(s) for ease of use in Visual Basic

http://www.thevbzone.com/d_DLL.htm

bdb
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 350 total points
ID: 9867992
Convert BMP to JPG with this code. (Note: Requires vic32.dll available from
http://www.catenary.com/)

'PLACE ALL THIS IN A NEW MODULE

Declare Function bmpinfo Lib "VIC32.DLL" (ByVal Fname As String, bdat As BITMAPINFOHEADER) 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 loadbmp Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes) As Long
Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Declare Function convert1bitto8bit Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes) As Long
Declare Sub copyimgdes Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes)
Declare Function savejpg Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes, ByVal quality As Long) As Long



' 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 BITMAPINFOHEADER
   biSize As Long
   biWidth As Long
   biHeight As Long
   biPlanes As Integer
   biBitCount As Integer
   biCompression As Long
   biSizeImage As Long
   biXPelsPerMeter As Long
   biYPelsPerMeter As Long
   biClrUsed As Long
   biClrImportant As Long
End Type

'PLACE THIS IN YOUR FORM DECLERATIONS

Private Sub ConvertToJPEG(bmp_fname As String, jpg_fname As String, Optional quality As Long)
  Dim tmpimage As imgdes    ' Image descriptors
  Dim tmp2image As imgdes
  Dim rcode As Long
  'Dim quality As Long
  Dim vbitcount 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"

  If quality = 0 Then quality = 75
 
   ' Get info on the file we're to load
  rcode = bmpinfo(bmp_fname, bdat)
  If (rcode <> NO_ERROR) Then
     msgbox "error: Unable to get file info"
     Exit Sub
  End If
   
  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.biWidth, bdat.biHeight, vbitcount)
  If (rcode <> NO_ERROR) Then
    msgbox "error: Not enough memory"
    Exit Sub
  End If
 
   ' Load image
  rcode = loadbmp(bmp_fname, tmpimage)
  If (rcode <> NO_ERROR) Then
     freeimage tmpimage ' Free image on error
     msgbox "error: Cannot load file"
     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.biWidth, 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
  Kill bmp_fname
  msgbox "picture saved: " & jpg_fname
     
End Sub
0
 
LVL 48

Assisted Solution

by:Mikal613
Mikal613 earned 350 total points
ID: 9868001
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 50 total points
ID: 9868747
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question