如何將bmp轉換爲vb6中的jpg?如何將bmp轉換爲vb6中的jpg
8
A
回答
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只有約250 kb。維克托圖書館的價格只有499美元,沒有分配版稅 – 2010-12-23 09:13:37
1
雖然有各種可用來保存其它格式的文件第三方控件,這些往往是「每座」有不可接受的許可政策及可不得了昂貴。本文介紹如何使用免費的JPEG DLL庫來保存VB圖片。
PS:支付$ 500,像VIC32庫只保存JPG圖像似乎太多...
2
與ImageMagick船舶它,這樣做
shell "convert.exe image.bmp image.jpg"
2
3
那麼,對於XP SP1和更高版本,您可以使用提供的工具:WIA 2.0庫。
爲了簡單地轉換BMP爲JPG你可以去掉近一半在這裏行:
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
對於XP,你需要將它部署:Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting。
對於以後的任何事情,它已經是操作系統的一部分。
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知道使用情況
相關問題
- 1. Android NDK:將.jpg轉換爲.bmp文件
- 2. 如何使用Objective C將.jpg圖像轉換爲.bmp格式?
- 3. 在Visual C++ 6.0中將.bmp轉換爲.jpg
- 4. 使用TJpegImage組件將bmp轉換爲jpg的問題
- 5. 如何將BMP轉換爲AVI C#
- 6. 如何將.Jpeg圖像轉換爲.Bmp
- 7. PHP - 將圖像從.jpg解壓並轉換爲.bmp
- 8. 將彩色bmp轉換爲灰度bmp?
- 9. 如何將任何類型(BMP,JPG等)圖像轉換爲DICOM圖像
- 10. 將emf轉換爲bmp
- 11. 將BMP轉換爲avi
- 12. 將Flash中的MovieClip轉換爲bmp
- 13. 如何將eps轉換爲jpg?
- 14. 如何將SERIESSUM函數轉換爲VB6?
- 15. 將文檔轉換爲Jpg
- 16. 將.eps轉換爲.jpg
- 17. 將TXT轉換爲JPG
- 18. 將JPG轉換爲HTML
- 19. c#將HTML轉換爲JPG
- 20. 將vb6轉換爲autoit
- 21. 如何將* .raw文件轉換爲JAVA中的* .bmp文件?
- 22. 如何將dicom文件轉換爲jpg轉換
- 23. 如何將html塊轉換爲asp.net中的圖像(例如jpg)
- 24. 如何把.SFF文件格式轉換爲.BMP或者.PNG或者.JPG文件?
- 25. 將24位bmp轉換爲16位?
- 26. 將pgm圖像轉換爲bmp
- 27. 使用PHP將.BMP轉換爲.PNG
- 28. 如何將jpg或png轉換爲IOS中的svg?
- 29. 如何將圖像(GIF,JPG,JPEG,PNG)轉換爲PHP中的TIFF?
- 30. 在Delphi 7中使用Paradox實時BMP到JPG轉換
不完全是一個重複,因爲你問BMP到JPG,但你可能也對[轉換GIF到JPG或TIF]這個問題感興趣(http://stackoverflow.com/問題/ 1333901/visual-basic-6-image-conversion-from-gif-to-jpg-or-tif) – MarkJ 2010-12-23 12:23:00
請參閱http://www.vbaccelerator.com/home/VB/Code/vbMedia/Saving_Pictures_to_JPG/Using_Intel_JPG_Library/有問題的article.asp Mark提到。 – 2010-12-23 14:57:48