Cómo convertir bmp a jpg en vb6?Cómo convertir bmp a jpg en vb6
Respuesta
cheque esta 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
El VIC32.DLL tiene solo unos 250 kb. El precio de Victor Library es de solo $ 499 sin regalías para su distribución –
Aunque hay varios controles de terceros disponibles para guardar archivos en otros formatos, éstos son a menudo tienen inaceptable 'por puesto' políticas de licencias y pueden ser increíblemente costoso. Este artículo muestra cómo usar una biblioteca de DLL JPEG gratuita para guardar imágenes VB.
PS: El pagar $ 500 para una biblioteca como VIC32 sólo para guardar las imágenes jpg parece demasiado ...
Barco con ImageMagick y hacer algo como
shell "convert.exe image.bmp image.jpg"
Bueno, para XP SP1 y posterior podría usar la herramienta proporcionada: la Biblioteca WIA 2.0.
simplemente convertir BMP a JPG se puede despojar a cabo casi la mitad de las líneas aquí:
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
Para XP que necesita para implementarlo: Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting.
Para nada más, ya forma parte del sistema operativo.
En XP, la DLL debe registrarse manualmente, ¿correcto? ¿Hay otra alternativa para registrarse? – Rick
@Rick Puede publicarlo como pregunta –
Cuando lo toma desde el archivo ZIP del SDK, necesita copiar WIAAut.dll a System32 y registrarlo.Pero para la redistribución usaría cualquier tecnología de instalación/instalación para implementarla, lo cual debería llevar a la instalación y registro como cualquier biblioteca ActiveX. – Bob77
¡Simplemente!
1) Este es el métodoCORTO:
SavePicture(LoadPicture("c:\YourFile.BMP"),"c:\YourFile.JPG")
2) Si desea convertir a cualquier formato (con/sin compresión), recomiendo FFMpeg.
Shell("ffmpeg.exe -i YourFile.bmp -q <qualityNumber*> ConverTo.Any")
* write ffmpeg /? en cmd para saber el uso
Si bien técnicamente cambia la extensión, en realidad no convierte el archivo a .jpg. Es solo un mapa de bits renombrado (según esto: http://msdn.microsoft.com/en-us/library/aa445827%28v=vs.60%29.aspx). – nerdherd
@nerdherd, lo entiendo. Pero dijo "convertir", no convertir con compresión;) – Searush
Solo quería asegurarme de que otros lectores estuvieran al tanto. +1 para agregar una opción alternativa para una conversión más útil. – nerdherd
- 1. Bmp a jpg/png en C#
- 2. Problema al convertir bmp a jpg usando TJpegImage Componente
- 3. Convertir imagen jpg a formato gif, png y bmp usando PHP
- 4. ¿Convertir imagen JPG/GIF a PNG en PHP?
- 5. Cómo convertir una imagen JPG a PNG
- 6. convertir tiff a formato jpg
- 7. Convertir BMP a PCX C# Compact Framework
- 8. PARA convertir formato .jpg a .eps
- 9. php imagick convertir PNG a jpg
- 10. Configuración de color de píxel del archivo BMP/JPG
- 11. Mostrar BMP en JLabel
- 12. PIL - Convertir Marcos GIF a JPG
- 13. C# convertir formatos de imagen a jpg
- 14. BufferedImage a BMP en Java
- 15. ¿Convertir bmp de 24 bits a 16 bits?
- 16. C# & VB6: ¿Cómo convertir la declaración 'con' a C#?
- 17. ¿Cómo puedo convertir el código VB6 a C#?
- 18. SVG a JPG/PNG
- 19. Cargar Jpg/Gif/Mapa de bits y convertir a mapa de bits
- 20. PIL Convertir PNG o GIF con transparencia a JPG sin
- 21. ¿Utiliza PHP para convertir PNG a JPG con compresión?
- 22. Convertidor de JPG a PDF en C#
- 23. png al bmp
- 24. conversión de fem a jpg
- 25. Convierta BMP a PNG en la memoria para que el Portapapeles pegue en .Net
- 26. sujetapapeles - convertir imágenes tiff en jpg o png
- 27. Conversión de imágenes .jpg a .png
- 28. cómo convertir un archivo avi a una matriz de imágenes jpg usando .net
- 29. Exportar PDF a JPG (s) en C#
- 30. ImageMagick PDF a JPG a veces resulta en fondo negro
No es exactamente un duplicado, porque ha preguntado acerca de BMP a JPG, pero también podría estar interesado en esta pregunta sobre [convertir GIF a JPG o TIF] (http://stackoverflow.com/ preguntas/1333901/visual-basic-6-image-conversion-from-gif-to-jpg-or-tif) – MarkJ
Ver http://www.vbaccelerator.com/home/VB/Code/vbMedia/Saving_Pictures_to_JPG/Using_Intel_JPG_Library/ article.asp en cuestión Mark mencionado. –