Home All Groups Group Topic Archive Search About

Need some help in compressing bmp file to jpeg file

Author
23 May 2005 4:52 PM
balu
Hi,

                 We are developing a visual basic application that
compresses  a bitmap file into jpeg file . We are not getting any solution
for compressing a bitmap file into jpeg file in visual basic. Eventhough we
had some solution ,  We are getting a problem with that solution . The
problem is that time taking to compress a bitmap file into jpeg file is
nearly 4 to 5 secs. but in vb.net , it is taking milliseconds and vb.net had
some built-in functions to do this where vb does not had. Our application
must be developed in vb.

Any kind of code or suggestions are appreciable.

Thank You .

Regards,
Balu.

Author
23 May 2005 5:26 PM
Mike D Sutton
>                  We are developing a visual basic application that
> compresses  a bitmap file into jpeg file . We are not getting any solution
> for compressing a bitmap file into jpeg file in visual basic. Eventhough we
> had some solution ,  We are getting a problem with that solution . The
> problem is that time taking to compress a bitmap file into jpeg file is
> nearly 4 to 5 secs. but in vb.net , it is taking milliseconds and vb.net had
> some built-in functions to do this where vb does not had. Our application
> must be developed in vb.

Easy on the cross-posting there, Balu, irrelevant groups snipped..
If you'd actually checked the groups you posted to before posting your own question, you'd have seen that this was
actually brought up yesterday on the m.p.winapi.graphics group, have a look at the thread entitled "How can i load jpeg
images faster than LoadPicture function" for a number of solutions.
Incidentally the "in-built" solution in VB.NET is the GDI+ graphics library which is also callable from VB, but as was
identified in the afore mentioned thread, may not be the fastest solution available.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
24 May 2005 7:38 AM
Andy DF
Here's a link to a great jpeg encoder class completely written in VB, NO
DEPENDECIES!
http://www.1cplusplusstreet.com/vb/scripts/ShowCode.asp?txtCodeId=50065&lngWId=1

Note that, as specified in the commented lines, the project has to be
compiled in order to achieve compression speed.
I just compressed an 11 MB bmp to a 100 KB jpeg in less the 2 secs on a PIV
2.8

HTH,

--
Andy,

andreaATdstudio32DOTit


Show quoteHide quote
"Mike D Sutton" <ED***@mvps.org> ha scritto nel messaggio
news:%23vDMJy7XFHA.3164@TK2MSFTNGP12.phx.gbl...
>>                  We are developing a visual basic application that
>> compresses  a bitmap file into jpeg file . We are not getting any
>> solution
>> for compressing a bitmap file into jpeg file in visual basic. Eventhough
>> we
>> had some solution ,  We are getting a problem with that solution . The
>> problem is that time taking to compress a bitmap file into jpeg file is
>> nearly 4 to 5 secs. but in vb.net , it is taking milliseconds and vb.net
>> had
>> some built-in functions to do this where vb does not had. Our application
>> must be developed in vb.
>
> Easy on the cross-posting there, Balu, irrelevant groups snipped..
> If you'd actually checked the groups you posted to before posting your own
> question, you'd have seen that this was
> actually brought up yesterday on the m.p.winapi.graphics group, have a
> look at the thread entitled "How can i load jpeg
> images faster than LoadPicture function" for a number of solutions.
> Incidentally the "in-built" solution in VB.NET is the GDI+ graphics
> library which is also callable from VB, but as was
> identified in the afore mentioned thread, may not be the fastest solution
> available.
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Author
23 May 2005 5:28 PM
Jonathan Wood
Balu,

>                  We are developing a visual basic application that
> compresses  a bitmap file into jpeg file . We are not getting any solution
> for compressing a bitmap file into jpeg file in visual basic. Eventhough
we
> had some solution ,  We are getting a problem with that solution . The
> problem is that time taking to compress a bitmap file into jpeg file is
> nearly 4 to 5 secs. but in vb.net , it is taking milliseconds and vb.net
had
> some built-in functions to do this where vb does not had. Our application
> must be developed in vb.

The .NET library has routines written in lower levels such as C and assembly
language. They tend to be very optimized, using some optimizations that may
not be available from VB.

That said, maybe your code isn't very optimized. Since the only information
I have is that it is too slow, I can only guess at what other optimizations
might be available.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Author
23 May 2005 5:29 PM
Dirk Goldgar
Show quote Hide quote
"balu" <b***@nannacomputers.com> wrote in message
news:uKvfOf7XFHA.2076@TK2MSFTNGP15.phx.gbl
> Hi,
>
>                  We are developing a visual basic application that
> compresses  a bitmap file into jpeg file . We are not getting any
> solution for compressing a bitmap file into jpeg file in visual
> basic. Eventhough we had some solution ,  We are getting a problem
> with that solution . The problem is that time taking to compress a
> bitmap file into jpeg file is nearly 4 to 5 secs. but in vb.net , it
> is taking milliseconds and vb.net had some built-in functions to do
> this where vb does not had. Our application must be developed in vb.
>
> Any kind of code or suggestions are appreciable.
>
> Thank You .
>
>  Regards,
> Balu.

Although it seems you're looking for a straight VB solution, since you
cross-posted this to an Access programming newsgroup, I'll point you to
a site containing an Access project that does what you're looking for.
If you separate the common VB aspects of the problem from the Access
object model, you may get find something useful.  See Stephen Lebans'
"LoadSaveJpeg" project at:

    http://www.lebans.com/loadsavejpeg.htm

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Author
24 May 2005 5:32 AM
J French
Show quote Hide quote
On Mon, 23 May 2005 22:22:20 +0530, "balu" <b***@nannacomputers.com>
wrote:

>Hi,
>
>                 We are developing a visual basic application that
>compresses  a bitmap file into jpeg file . We are not getting any solution
>for compressing a bitmap file into jpeg file in visual basic. Eventhough we
>had some solution ,  We are getting a problem with that solution . The
>problem is that time taking to compress a bitmap file into jpeg file is
>nearly 4 to 5 secs. but in vb.net , it is taking milliseconds and vb.net had
>some built-in functions to do this where vb does not had. Our application
>must be developed in vb.
>
>Any kind of code or suggestions are appreciable.

See :-

http://www.jerryfrench.co.uk/pictojpg.htm

Save a VB PictureBox.Picture, PictureBox.Image or StdPicture
to a .JPG file
Author
24 May 2005 2:19 PM
Martin
You can use GDI+ API to save picture from stdPicture object in jpeg file
format.
You can find GDI+ on microsoft web site
http://www.microsoft.com/downloads/details.aspx?FamilyID=6a63ab9c-df12-4d41-933c-be590feaa05a&DisplayLang=en

Place the code below in standard module.
For example you can create a form with PictureBox.
Load bitmap into PictureBox and use SaveJPG function to save picture as jpg.

Option Explicit

' ----==== API Declarations ====----

Private Type GUID
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4(0 To 7) As Byte
End Type

Private Type GdiplusStartupInput
   GdiplusVersion As Long
   DebugEventCallback As Long
   SuppressBackgroundThread As Long
   SuppressExternalCodecs As Long
End Type

Private Type EncoderParameter
   GUID As GUID
   NumberOfValues As Long
   Type As Long
   Value As Long
End Type

Private Type EncoderParameters
   Count As Long
   Parameter As EncoderParameter
End Type

Private Declare Function GdiplusStartup Lib "GDIPlus" ( _
   token As Long, _
   inputbuf As GdiplusStartupInput, _
   Optional ByVal outputbuf As Long = 0) As Long

Private Declare Function GdiplusShutdown Lib "GDIPlus" ( _
   ByVal token As Long) As Long

Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" ( _
   ByVal hbm As Long, _
   ByVal hPal As Long, _
   Bitmap As Long) As Long

Private Declare Function GdipDisposeImage Lib "GDIPlus" ( _
   ByVal Image As Long) As Long

Private Declare Function GdipSaveImageToFile Lib "GDIPlus" ( _
   ByVal Image As Long, _
   ByVal filename As Long, _
   clsidEncoder As GUID, _
   encoderParams As Any) As Long

Private Declare Function CLSIDFromString Lib "ole32" ( _
   ByVal str As Long, _
   id As GUID) As Long

' ----==== SaveJPG ====----

Public Sub SaveJPG( _
   ByVal pict As StdPicture, _
   ByVal filename As String, _
   Optional ByVal quality As Byte = 80)
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long

   ' Initialize GDI+
   tSI.GdiplusVersion = 1
   lRes = GdiplusStartup(lGDIP, tSI)

   If lRes = 0 Then

      ' Create the GDI+ bitmap
      ' from the image handle
      lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)

      If lRes = 0 Then
         Dim tJpgEncoder As GUID
         Dim tParams As EncoderParameters

         ' Initialize the encoder GUID
         CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), _
                         tJpgEncoder

         ' Initialize the encoder parameters
         tParams.Count = 1
         With tParams.Parameter ' Quality
            ' Set the Quality GUID
            CLSIDFromString
StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
            .NumberOfValues = 1
            .Type = 4
            .Value = VarPtr(quality)
         End With

         ' Save the image
         lRes = GdipSaveImageToFile( _
                  lBitmap, _
                  StrPtr(filename), _
                  tJpgEncoder, _
                  tParams)

         ' Destroy the bitmap
         GdipDisposeImage lBitmap

      End If

      ' Shutdown GDI+
      GdiplusShutdown lGDIP

   End If

   If lRes Then
      Err.Raise 5, , "Cannot save the image. GDI+ Error:" & lRes
   End If

End Sub


Show quoteHide quote
"balu" <b***@nannacomputers.com> wrote in message
news:uKvfOf7XFHA.2076@TK2MSFTNGP15.phx.gbl...
> Hi,
>
>                  We are developing a visual basic application that
> compresses  a bitmap file into jpeg file . We are not getting any solution
> for compressing a bitmap file into jpeg file in visual basic. Eventhough
we
> had some solution ,  We are getting a problem with that solution . The
> problem is that time taking to compress a bitmap file into jpeg file is
> nearly 4 to 5 secs. but in vb.net , it is taking milliseconds and vb.net
had
> some built-in functions to do this where vb does not had. Our application
> must be developed in vb.
>
> Any kind of code or suggestions are appreciable.
>
> Thank You .
>
>  Regards,
> Balu.
>
>
>
>