环境: d:as 目录下 有很多图片,图片的名字 对应 newtrj 这个表的 cn_name列(cn_name只是前缀,例如图片名为11.jpg cn_name =11)
目的: 把as目录下 图片名能和cn_name列相同的图片 打上二维码。
用下面这段代码执行了,有的时候可以顺利执行,有的时候不可以,不知道是什么原因,请各位给指点下。 非常感谢
Dim Bar As New BarCodeBuilder
Dim doc As New PrintDoc
Dim rt As new prt.RenderText
Bar.Symbology = Barpro.Symbology.QRCode
Bar.BarRatio =0.5
Bar.BarWidth = 1
Bar.BarHeight = 1
Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight
For Each r As DataRow In DataTables("newtrj").Select("id> 0") '从数据表中提取数据
bar.Code = r("qrcord")
Dim fn As String = ""
fn = "(1):" & r("cn_name")
If fn <> "" And filesys.FileExists("d:\as\" & fn & ".jpg") = True Then
Dim route As String ="d:\as\" & fn & ".jpg" '原始照片存放路径
Dim route2 As String ="d:\qrcord\" & fn & ".jpg"
Dim zwidth = getImage(route).width '原始照片宽
Dim zheight = getImage(route).height '原始照片高
Dim p As WinForm.Painter =e.Form.CreateControl("p", ControlTypeEnum.Painter)
p.Width = zwidth '原始照片宽动态赋给画板宽
p.Height = zheight '原始照片高动态赋给画板高
Dim g As Graphics = p.Graphics
g.Clear(Color.White)
g.DrawImage(getImage(route),3,3,zwidth,zheight)
g.DrawImage(bar.GetImage,(zwidth-10),(zheight-1800),250,250)
Dim rm As New prt.RenderImage '定义一个图片对象
rm.Image = GetImage("archives.ico") '设置图片
rm.Style.ImageAlign.StretchHorz = True '水平拉伸
g.DrawImage(rm.Image,(zwidth-50),(zheight-50),30,30) '二维码图片位置
Dim fnt As New Font("黑体",20,FontStyle.Bold) '黑体,10号,加粗
g.DrawString(fn,fnt,Brushes.Black,(zwidth-280),(zheight-200))
p.Repaint()
Dim img As Image = p.Image
p.Save(route2)
img.save(route2)
End If
Next
MessageBox.Show("全部添加成功!", "提示")