2017-03-08 51 views
0

我正在用KeepAutomation构建Code 128条形码的Label打印机。打印后不能删除VB.NET中的条形码图像(KeepAutomation)

在该过程实际上我:

  1. 编码数据与KeepAutomation引用模块

    Private Sub MakeImage() 
    Dim barcode As KeepAutomation.Barcode.Bean.BarCode = New KeepAutomation.Barcode.Bean.BarCode 
    barcode.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto 
    barcode.CodeToEncode = Me.txtCatNum.Text 
    barcode.X = 2 
    barcode.Y = 100 
    barcode.BottomMargin = 0 
    barcode.LeftMargin = 0 
    barcode.RightMargin = 0 
    barcode.TopMargin = 0 
    barcode.DisplayText = True 
    barcode.ChecksumEnabled = True 
    barcode.DisplayChecksum = True 
    barcode.Orientation = KeepAutomation.Barcode.Orientation.Degree0 
    barcode.BarcodeUnit = KeepAutomation.Barcode.BarcodeUnit.Pixel 
    barcode.DPI = 72 
    barcode.TextFont = New Font("Arial", 26.0F, FontStyle.Regular) 
    barcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg 
    barcode.generateBarcodeToImageFile(FileToUse)     
    
  2. 条形码创建从编码数据的JPEG图像(具有静态名称给硬盘驱动器上的特定位置)

  3. 将图像放置在PrintDocument中

  4. 打印

但是当我尝试删除该文件之前,我再次运行该程序,它告诉我,它不能删除该文件,因为它使用由应用程序本身,如果出版)或vshost32- clr2.exe(在调试时)。

我曾尝试:

  1. 处置PrintDocument类

  2. 处置,关闭并重新打开窗体本身。

以上都不对我有帮助。

寻找一个好主意(其他然后创建创建每个标签不同的图像)

感谢, 盖伊

+0

“条码”是否可以一次性使用? – pinkfloydx33

+0

不,找了它,找不到任何方式来处理它 – RobinHud

+0

什么是FileToUse?它是一个字符串还是一个流 – pinkfloydx33

回答

0

感谢朋友,

我找到了完美的答案我的问题从pinkfloydx33

我已经为我创建的jpeg创建了一个FileStream,打开它作为“只读”,并且一旦完成将它放在PrintDocument类上,我可以很容易地覆盖/ De lete它。

这是我使用的代码.....

 MakeImage() 
    Dim fs As New FileStream(FileToUse, FileMode.Open, FileAccess.Read) 
    e.Graphics.DrawImage(Image.FromStream(fs), 20, 5, 150, 80) 
    e.Graphics.DrawString("Batch: ___________", BatchFont, Brushes.Black, 0, 97) 
    fs.Dispose() 

结论,如果可以的话.....

每当你打开一个文件时,尤其是当你不需要修改,将其作为FS访问并打开为ReadOnly .....

再次感谢。