手机上下载的JPG图片,Picture和Image都加载显示不了?
VB如何写代码才能格式化这些图片,转成能够显示的JPG或BMP图,类似格式化工厂……
后缀是jpg不一定就是jpg, JPG格式图片的判断依据是第一个字节和第二个字节的数据是0xff和0xd8,倒数第一个和倒数第二个字节数据分别是0xd9和0xff,如果都对,那么判断此数据为jpg图片数据!
先确定你的图片是否是jpg
Private Sub Form_Load() Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" Set IMG = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") IMG.LoadFile "test.bmp" IP.Filters.Add IP.FilterInfos("Convert").FilterID IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG Set IMG = IP.Apply(IMG) IMG.SaveFile "test.jpg" End Sub
[此贴子已经被作者于2023-11-5 19:18编辑过]
[此贴子已经被作者于2023-10-31 12:27编辑过]
Private Sub Form_Load() Const wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}" Set IMG = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") IMG.LoadFile "D:\Demo\123.jpg" IP.Filters.Add IP.FilterInfos("Convert").FilterID IP.Filters(1).Properties("FormatID").Value = wiaFormatBMP Set IMG = IP.Apply(IMG) IMG.SaveFile "D:\Demo\123.bmp" Dim pp As StdPicture Picture1.AutoRedraw = True Set pp = LoadPicture("D:\Demo\123.bmp") Picture1.PaintPicture pp, 0, 0, Picture1.Width, Picture1.Height End Sub
[此贴子已经被作者于2023-11-5 19:19编辑过]