2010-12-23 3 views
8

bmp를 vb6에서 jpg로 변환하는 방법은 무엇입니까?bbmp를 jpg로 변환하는 방법

+0

BMP를 JPG에 대해 질문했기 때문에 정확히 중복되지는 않지만 [GIF를 JPG 또는 TIF로 변환] (http://stackoverflow.com/)에서이 질문에 관심이있을 수 있습니다. 질문/1333901/visual-basic-6-image-conversion-from-gif-to-jpg-or-tif) – MarkJ

+1

http://www.vbaccelerator.com/home/VB/Code/vbMedia/Saving_Pictures_to_JPG/Using_Intel_JPG_Library/를 참조하십시오. 문제의 article.asp 언급 된 마크. –

답변

3

확인이 link

'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

VIC32.DLL은 약 250kb입니다. Victor Library 가격은 $ 499이며 배포료는 없습니다. –

1

From here: 다른 형식으로 파일을 저장 사용할 수있는 다양한 타사 컨트롤이는 종종 '좌석 당'받아 들일 수있는 라이선스 정책과 믿을 수 없을만큼 될 수 있습니다 동안

비싼. 이 기사에서는 무료 JPEG DLL 라이브러리를 사용하여 VB 사진을 저장하는 방법을 보여줍니다. PS

: 그냥 JPG 이미지를 저장하기위한 VIC32 같은 라이브러리 $ 500 지불하는 것은 너무 많은 것 같다 ...

2

ImageMagick 우주선을하고 무언가 같은

shell "convert.exe image.bmp image.jpg" 
+0

파일이 네트워크 공유에있을 때 작동하지 않습니다. 이 문제를 어떻게 해결할 수 있습니까? – Rick

+0

@Rick 먼저 로컬 드라이브에 복사합니까? 나는 ImageMagick이 네트워크 공유에서 파일을 작동시키지 않는다는 것을 알지 못했다. 네트워크 공유에 대한 경험이 없습니다. – Robert

2

당신은 use GDI+ 수 VB6에서에 JPG에 저장하십시오.

+0

Gave +는 Windows 서비스에서는 안전하지 않으며 IIS에서도 안전하지 않은 것으로 보입니다. – Bob77

3

XP SP1 이상에서는 제공된 도구 인 WIA 2.0 라이브러리를 사용할 수 있습니다. 당신이해야합니다 XP의

Option Explicit 
' 
'Requires a reference to: 
' Microsoft Windows Image Acquisition Library v2.0 
' 

Private Const TIFF_LZW As String = "LZW" 
Private Const TIFF_RLE As String = "RLE"  'Pixel Depth must be 1. 
Private Const TIFF_CCITT3 As String = "CCITT3" 'Pixel Depth must be 1. 
Private Const TIFF_CCITT4 As String = "CCITT4" 'Pixel Depth must be 1. 
Private Const TIFF_Uncompressed As String = "Uncompressed" 

Private Sub ImgConvert(_ 
    ByVal InFileName As String, _ 
    ByVal OutFileName As String, _ 
    ByVal OutFormat As String, _ 
    Optional ByVal Quality As Integer = 100, _ 
    Optional ByVal Compression As String = TIFF_LZW) 

    Dim Img As WIA.ImageFile 
    Dim ImgProc As WIA.ImageProcess 

    Set Img = New WIA.ImageFile 
    Img.LoadFile InFileName 
    Set ImgProc = New WIA.ImageProcess 
    With ImgProc.Filters 
     .Add ImgProc.FilterInfos("Convert").FilterID 
     .Item(1).Properties("FormatID").Value = OutFormat 
     If OutFormat = wiaFormatJPEG Then 
      .Item(1).Properties("Quality").Value = Quality 
     ElseIf OutFormat = wiaFormatTIFF Then 
      .Item(1).Properties("Compression").Value = Compression 
     End If 
    End With 
    Set Img = ImgProc.Apply(Img) 

    On Error Resume Next 
    Kill OutFileName 
    On Error GoTo 0 
    Img.SaveFile OutFileName 
End Sub 

Private Sub Main() 
    ImgConvert "sample.bmp", "sample.jpg", wiaFormatJPEG, 70 
    ImgConvert "sample.bmp", "sample.gif", wiaFormatGIF 
    ImgConvert "sample.bmp", "sample.png", wiaFormatPNG 
    ImgConvert "sample.bmp", "sample.tif", wiaFormatTIFF, , TIFF_Uncompressed 
    MsgBox "Complete" 
End Sub 

그것을 배포 : Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting

은 단순히 당신이 여기에 라인의 거의 절반을 제거 할 수 있습니다 JPG로 BMP로 변환합니다.

나중에 어떤 것이 든 그것은 이미 OS의 일부입니다.

+0

XP에서 DLL을 수동으로 올바르게 등록해야합니까? 등록 할 다른 방법이 있습니까? – Rick

+0

@Rick 질문으로 게시 할 수 있습니다. –

+0

SDK의 ZIP 아카이브에서 가져올 때 WIAAut.dll을 System32로 복사하고 등록해야합니다.그러나 재배포를 위해서는 설치/설치 프로그램 기술을 사용하여 배포해야합니다. ActiveX 라이브러리와 마찬가지로 설치 및 등록을해야합니다. – Bob77

2

간단히!
1)은 최단 방법 :

SavePicture(LoadPicture("c:\YourFile.BMP"),"c:\YourFile.JPG") 

2) 당신이 어떤 형식 (와/압축없이)로 변환 할 경우에, 나는 FFMpeg을 추천합니다.

Shell("ffmpeg.exe -i YourFile.bmp -q <qualityNumber*> ConverTo.Any") 

* write ffmpeg /? cmd 사용법을 알아야합니다

+0

확장 기능을 기술적으로 변경하는 동안 실제로 파일을 .jpg로 변환하지 않습니다. 이름이 바뀐 비트 맵입니다 (http://msdn.microsoft.com/en-us/library/aa445827%28v=60.aspx). – nerdherd

+0

@nerdherd, 이해합니다. 하지만 그는 "변환"이라고 말하며 압축으로 변환하지는 않습니다.) – Searush

+0

다른 독자가 알고 있는지 확인하고 싶었습니다. 더 유용한 전환을위한 대체 옵션 추가에 +1. – nerdherd

관련 문제