Solved

BMP to GIF Conversion

Posted on 2001-08-17
8
559 Views
Last Modified: 2013-11-19
Hi Experts

i'm facing a problem in converting an image from BMP to GIF or JPG. i've an active x control which does the same thing. but i do not want to use any controls in my software.

my .exe should run without any dependencies.

can anybody give me some info. about how can i write an algo. to convert BMP to GIF. that should preferably in VB.


habib
0
Comment
Question by:h_rangoonwala
[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
8 Comments
 
LVL 3

Expert Comment

by:SirNick
ID: 6396247
I'm not sure whether this is any use, someone gave it to me the other day.  It changes a jpg to bmp, but you might be able to change it to the other way around.


Sub JPGtoBMP ()
LoadPic = LoadPicture(App.Path & "background.jpg")
SavePic = LoadPic
SavePicture SavePic.Picture, App.Path & "background.bmp"
End Sub

0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6396251
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6396659
DreamMaster - h_rangoonwala says he doesn't want to run with any dependencies. That link, although useful is an OCX, unfortunately.

I have seen proper VB code for saving from VB to GIF but it's rather complicated - I'll see if I can track it down. Most people in the situation usually resort to a third party DLL or EXE for this task.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 19

Expert Comment

by:DreamMaster
ID: 6396693
Oops...I missed that line....

I'm sorry...thanks for pointing that out nutwiss....

I'll see if I can find "proper" VB code as well....

Max.
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6397147
Hi,

GIF is a proprietary format, you will need to pay a lisence fee if you want to have your own code doing the conversion. I think the company that owns it is called unisys, but I don't remember.

Zaaphod.
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6397168
yes it is - ignore unisys... everyone else does... and anyway the patent expires in september 2003...
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 100 total points
ID: 6397899
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
 

Author Comment

by:h_rangoonwala
ID: 6402862
Thank u very much.

it helped me a lot

habib
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 477
Slow Printing 8 162
MsgBox 4 76
Email Excel WB by selecting name from a dropdown  list to Outlook. 5 47
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…

739 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