martin2k

Home | Forums | VB6 | Games | Software | Directory | HTML | Wiki | Blog | Contact

How do you save JPEG images?


 

Home

Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here

Contact


 

Question

From: Björn
Date: Wednesday 27 February 2002 10:29 AM
Subject: About saveas function
Question: Hi, I wonder how to use the SaveAs function to save the Picture as *.jpg?

Regards Bjorn

Using SavePicture, you can only save pictures (gif, jpg and bmp) as bitmaps or icons as icons.  You would need an ActiveX control or something to write pictures in jpg format.  There is a free one called PicFormat32 available here:

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=13267&lngWId=1

I haven't tried it yet, but if anyone finds it useful, please add a message below.

Update at Friday 5 December 2003 5:02 PM

For some reason, the DLL and OCX files are not available at Planet Source Code.  They can be downloaded from this address:

http://www.geocities.com/the_rancid/files/MajestyLibrary101.zip (188 KB)

Update by SuperMidget at Sunday, May 2, 2004 at 16:39:56

The "Majesty" library with Picformat32.dll & ocx isn't available at geocities anymore... it is still on fileplanet, apperently.

http://www.fileplanet.com/download.aspx?f=62236

Cheers, SuperMidget


blog comments powered by Disqus

Archived Comments

From: Steve
Date: Sunday, September 19, 2010 at 22:00:52
Comments: The sample code worked great!  I had to download the vic32.dll, but after that there were no problems.  I simply cut, pasted, and changed the source.bmp and output.jpg names and it worked.  Thanks so much.
 
From: jaydev
Date: Wednesday, May 16, 2007 at 08:39:10
Comments: .............................
      File VIC32.DLL Not Found
 
From: stefano
Date: Saturday, May 8, 2004 at 19:49:21
Comments: the pict..32 is available only at:

http://www.vbcode.com/Asp/showzip.asp?ZipFile=http%3A%2F%2Fwww%2Evbcode%2Ecom%2Fcode%2FPicFormat32a%2Ezip&theID=2679

Many thanks for the other info !!!

 
From: vanz
Date: Wednesday, April 28, 2004 at 08:19:48
Comments: Hi archana,
Iffy here
plz check out this article.
This ones very relevant to what you asked me.
All da best!! :)
 
From: MohammedRasol
Date: Monday, March 1, 2004 at 09:50:50
Comments: Hi, i wonder to know how to read *.jpeg files from the memory to an external buffer(e.g  pc memo to digital camera buffer)in VB code
 
Reply:

If the digital camera acts like another drive on your computer, you can use the FileCopy statement to copy the file onto it.  E.g.:

FileCopy "C:\Files\Pic1.jpg", "G:\Pic1.jpg"
 
From: Bihshan
Date: Wednesday, October 22, 2003 at 09:21:14
Comments: I had applied the source code and the vic32.dll.
When the program was excuted, the message showed "not enough memory"?
Why did the problem came up?
How much memory should I have?
 
From: khusro
Date: Thursday, October 16, 2003 at 20:33:13
Comments: how to download vic32.dll file pls send mail
 
Reply: I don't think you can download this for free.  You will have to pay for it.  One place it can be bought from is Catenary Systems.  It isn't cheap at $499, however.  For a free way to save JPEG images, try PicFormat32.
 
From: loopa chakraborty <red_rosemarry @ yahoo.co.in>
Date: Saturday, October 11, 2003 at 15:56:11
Comments: in the code given in the net and mentioned below where do i declare the following
[Declare Function bmpinfo Lib "VIC32.DLL" (ByVal Fname As String, bdat As BITMAPINFOHEADER) As Long]
etc.
 
Reply: You put this code in the General Declarations section of your code.
 
From: loopa chakraborty <red_rosemarry @ yahoo.co.in>
Date: Friday, October 10, 2003 at 16:58:38
Comments: to convert bmp files to jpg file i am usin vic32.dll
do i need to register this dll ?if so how to register it
while converting how do i load the bmp file and allocate workspace to convert to jpg
 
From: loopa chakraborty <red_rosemarry>
Date: Thursday, September 4, 2003 at 11:47:14
Comments: what is victor Image Processing Library
 
Reply: From http://www.catenary.com/:

"The Victor Image Processing Library is an application developers' image toolkit, a collection of functions that allow you to create image applications. Victor gives your programs powerful image processing, color reduction, display, TWAIN scanning, printing, file handling, and converting capabilities.

"Create your applications in Visual Basic, VB.NET, C/C++, Java, or any other programming language and give them support for BMP, GIF, JPEG, PCX, PNG, TGA, and TIFF image file formats."

 
From: Bojan
Date: Tuesday, February 18, 2003 at 08:54:57
Comments: I've tried it out and it works perfect, the only 'problem' is: it works with files on disk, so you have to save your picture temporarily as bmp, then use PicFormat to convert it, and then delete the temp bmp.
 
From: parthajedi
Date: Wednesday, February 5, 2003 at 02:33:48 
Comments: http://www.catenary.com/howto/bmp2jpeg.html

BMP to JPEG - the Visual Basic Source Code
Requires Victor Image Processing Library for 32-bit Windows v 5 or higher.

Private Sub mnuconvertBMPtoJPG_Click()
  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"

  quality = 75
  ' Get info on the file we're to load
  rcode = bmpinfo(bmp_fname, bdat)
  If (rcode <> NO_ERROR) Then
      MsgBox "Cannot find file", 0, "Error encountered!"
      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 "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.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

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 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

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

 
Martin Allen 1999 - 2011.  Last updated Tuesday 09 August 2011 08:07:08 PM +0100.