我有一个访问数据库,我的平装书收集,使用VB下载和保存条形码文件从一个免费的在线服务。脚本将它们保存为.png文件,并将它们显示为表单和报表中的图像对象(我认为如果我的书籍丢失、被盗或被销毁,使用ISBN和/或UPC代码识别图书可以帮助确定损失的值)。
有一个特定的条形码不能由网站生成,但我可以自己制作它,下载两个条形码图像,裁剪一个,附加到第二个图像,然后将结果保存为第三个图像。之后,可以丢弃(删除)下载的图像,并在“我的访问表单和报表”中将其作为图像对象使用。
ImageA.png大小为688x209像素(称为ISBN 13+5条形码,左侧为13位EAN样式条码,右侧为5位价格条形码)。
ImageB.png的大小为471x209像素(这是一个标准的12位UPC条形码,从DVD到洗手机、威士忌瓶到汽车电池,无所不包)。
在VB中,我想要做的是从ImageA的左侧裁剪450个像素,有效地从图像中剥离EAN代码,然后保存留在ImageA.png或TempA.png中的238x209像素.然后,我想把它附加到ImageB.png的右侧,并将合并的图像保存为ImageC.png (709x209像素)。该组合动作有效地提取了"EAN + 5“条形码图像,剥离了EAN码,然后用UPC码代替了EAN码。
通过查看以下内容可能更容易理解我想要做的事情:一步一步的图形示例
保存ImageC.png后,可以删除ImageA.png和/或TempA.png和ImageB.png。我真正想要的就是ImageC.png。
我希望我能提供示例代码,但无论我看什么地方,我都看到显示图片框或需要鼠标移动的代码示例-下载的图像将始终是相同的大小,所以我只想加载和裁剪图像而不显示它.然后把它附加到第二张图片上保存.然后,我想要显示结果的复合图像。
谢谢您抽时间见我。
发布于 2021-07-20 02:05:21
我想我明白了..。
ShortISBN = Mid((LongISBNString), 5, 5) 'sets 5-digit string for filename
ShortISBNFile = [ShortISBN] & ".png" 'sets the new filename
Set IP = CreateObject("WIA.ImageProcess") 'create WIA objects
Set Img = CreateObject("WIA.ImageFile")
Img.LoadFile CurrentProject.Path & "\temp.png" 'load downloaded image
IP.Filters.Add IP.FilterInfos("Crop").FilterID 'setup crop filter
With IP.Filters(1)
.Properties("Left") = 450
End With
Set Img = IP.Apply(Img) 'apply change
Img.SaveFile CurrentProject.Path & [ShortISBNFile] 'save image with new filename
Kill CurrentProject.Path & "\temp.png" 'delete downloaded image
至于合并两个图像,https://www.vbforums.com/showthread.php?725361-RESOLVED-merge-two-scanned-images-into-one似乎有答案,但是代码的格式不同,当我逐字复制并粘贴到我的项目中时,会抛出一个错误.但是,我稍微修改了一下代码的格式,以反映剪切代码中使用的格式,这似乎纠正了错误:
Dim oIF1 As Object, oIF2 As Object, oVectNew As Object, oIFNew As Object
Dim oIP As Object, TempCodeFile As String, lPixelsWide As Long, lPixelsHigh As Long
ShortISBN = Mid([ISBN Number], 7, 5)
ShortISBNFile = Mid([ISBN Number], 7, 5) & ".png"
Set oIF1 = CreateObject("WIA.ImageFile")
With oIF1
.LoadFile CurrentProject.Path & [UPCCodeFile]
lPixelsWide = .Width
lPixelsHigh = .Height
End With
Set oIF2 = CreateObject("WIA.ImageFile")
With oIF2
.LoadFile CurrentProject.Path & [ShortISBNFile]
lPixelsWide = lPixelsWide + .Width
End With
With New BmpGen 'This is the Class Module from the above link
Set oVectNew = CreateObject("WIA.Vector")
oVectNew.BinaryData = .MakeMono(BG_COLOR, lPixelsWide, lPixelsHigh)
End With
Set oIFNew = oVectNew.ImageFile
Set oVectNew = Nothing
Set oIP = CreateObject("WIA.ImageProcess") 'create WIA objects
With oIP
oIP.Filters.Add oIP.FilterInfos("Stamp").FilterID
With oIP.Filters(1)
Set .Properties("ImageFile") = oIF1
.Properties("Left") = 0
.Properties("Top") = 0
End With
oIP.Filters.Add oIP.FilterInfos("Stamp").FilterID
With oIP.Filters(2)
Set .Properties("ImageFile") = oIF2
.Properties("Left") = oIF1.Width
.Properties("Top") = 0
End With
Set oIFNew = oIP.Apply(oIFNew)
End With
TempCodeFile = left([UPCCodeFile], 15) & " " & [ShortISBNFile]
UPCCodeFile = TempCodeFile
oIFNew.SaveFile CurrentProject.Path & [UPCCodeFile]
Kill CurrentProject.Path & [ShortISBNFile]
我应该在代码生成过程中进行一些错误检查(如果UPC代码字符串太短或太长怎么办?)但是最后,当你真的不知道你在做什么的时候,你能做什么是令人惊奇的。
https://stackoverflow.com/questions/68426345
复制相似问题