CreateObject("WIA.ImageFile") ,Multiple image format conversion
Code:Const wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatGIF = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatTIFF = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" Sub WIA_Tojpg(srcFileName As String, JpgFile As String, Optional Quality As Long = 80) ' setup the image processor Dim prc, img Set prc = CreateObject("WIA.ImageProcess") With prc.Filters .Add prc.FilterInfos("Convert").FilterID .Item(1).Properties("FormatID").Value = wiaFormatJPEG If Quality > 0 Then .Item(1).Properties("Quality").Value = Quality ' 100% End With ' image object Set img = CreateObject("WIA.ImageFile") ' load, process and save the file img.LoadFile srcFileName Set img = prc.Apply(img) img.SaveFile JpgFile End Sub Sub TestWIA_PicTo() WIA_PicTo App.Path & "\002.bmp", App.Path & "\002_togif.gif", wiaFormatGIF, -1 End Sub Sub WIA_PicTo(srcFileName As String, ToFile As String, Optional FormatID As String = wiaFormatJPEG, Optional Quality As Long = 80) ' setup the image processor Dim prc, img Set prc = CreateObject("WIA.ImageProcess") With prc.Filters .Add prc.FilterInfos("Convert").FilterID .Item(1).Properties("FormatID").Value = FormatID If Quality > 0 Then .Item(1).Properties("Quality").Value = Quality ' 100% End With ' image object Set img = CreateObject("WIA.ImageFile") ' load, process and save the file img.LoadFile srcFileName Set img = prc.Apply(img) img.SaveFile ToFile End Sub




Reply With Quote