2010-12-23 14 views
8

Wie bmp in jpg in vb6 konvertieren?Wie bmp in jpg in vb6 konvertieren

+0

Nicht genau ein Duplikat, weil Sie über BMP zu JPG gefragt haben, aber Sie könnten auch an dieser Frage interessiert sein [Konvertierung von GIF nach JPG oder TIF] (http://stackoverflow.com/ Fragen/1333901/Visual-Basic-6-Bild-Konvertierung-von-GIF-zu-JPG-oder-TIF) – MarkJ

+1

Siehe http://www.vbaccelerator.com/home/VB/Code/vbMedia/Saving_Pictures_to_JPG/Using_Intel_JPG_Library/ article.asp in Frage Mark erwähnt. –

Antwort

3

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

Die VIC32.DLL ist nur etwa 250 kb. Der Victor-Bibliothekspreis beträgt nur 499 USD ohne Lizenzgebühren für die Verteilung. –

1

From here:

Während verschiedene Kontrollen von Drittanbietern zur Verfügung zu speichern Dateien in anderen Formaten gibt es, diese sind oft nicht akzeptabel "pro Sitz Politik der Lizenzierung und kann unglaublich sein teuer. Dieser Artikel beschreibt, wie eine freie JPEG DLL-Bibliothek zu dem Speichern von VB-Bildern verwandt wird.

PS: für eine Bibliothek $ 500 Bezahlen wie VIC32 nur für das Speichern von JPG-Bilder zu viel scheint ...

2

Schiff mit ImageMagick und etwas tun, wie

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

Es funktioniert nicht, wenn sich die Dateien in einer Netzwerkfreigabe befinden. Wie kann ich das umgehen? – Rick

+0

@Rick Kopieren Sie sie zuerst auf ein lokales Laufwerk? Ich wusste nicht, dass ImageMagick Dateien in einer Netzwerkfreigabe nicht funktioniert. Ich habe keine Erfahrung mit Netzwerkfreigaben. – Robert

2

Sie können use GDI+ von VB6 Speichern in JPG.

+0

Vorsicht: GDI + ist in einem Windows-Dienst nicht sicher und scheint auch unter IIS nicht sicher zu laufen. – Bob77

3

Nun, für XP SP1 und höher können Sie das mitgelieferte Tool verwenden: die WIA 2.0 Library.

einfach BMP konvertieren Sie JPG können hier fast die Hälfte der Linien Streifen aus:

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 

Für XP Sie es einsetzen benötigen: Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting.

Für alles später ist es bereits Teil des Betriebssystems.

+0

In XP muss die DLL manuell registriert werden, richtig? Gibt es eine andere Alternative zur Registrierung? – Rick

+0

@Rick Sie könnten dies als Frage –

+0

Wenn Sie es aus dem ZIP-Archiv des SDK nehmen, müssen Sie WIAAut.dll zu System32 kopieren und registrieren.Aber für die Neuverteilung würden Sie jede Setup-/Installer-Technologie verwenden, um sie zu installieren, die es wie jede ActiveX-Bibliothek installieren und registrieren sollte. – Bob77

2

Einfach!
1) Dies ist die KÜRZESTE Methode:

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

2) Wenn Sie in ein beliebiges Format konvertieren möchten (mit/ohne Kompression), empfehle ich FFMpeg.

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

* schreiben ffmpeg /? in cmd zu wissen Verwendung

+0

Während die Erweiterung technisch geändert wird, wird die Datei nicht in .jpg konvertiert. Es ist nur eine umbenannte Bitmap (entsprechend: http://msdn.microsoft.com/en-us/library/aa445827%28v=vs.60%29.aspx). – nerdherd

+0

@nerdherd, ich verstehe. Aber er sagte "konvertieren", nicht mit Kompression konvertieren;) – Searush

+0

wollte nur sicherstellen, dass andere Leser bewusst waren. +1 für das Hinzufügen einer alternativen Option für eine nützlichere Konvertierung. – nerdherd

Verwandte Themen