打印后无法在VB.NET中删除aBarcode图像(KeepAutomation)

时间:2017-03-08 09:23:41

标签: vb.net

我正在使用KeepAutomation构建一个带Code 128条码的Label打印机。

在程序中我实际上:

  1. 使用KeepAutomation Referenced模块将数据编码到条形码

    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. 打印

  5. 但是当我在再次运行该程序之前尝试删除该文件时,它告诉我它无法删除该文件,因为它被应用程序本身(如果已发布)或vshost32-clr2.exe(在调试时)使用。

    我试过了:

    1. 处理PrintDocument类

    2. 处理,关闭和重新开始表单。

    3. 以上都没有帮助过我。

      寻找一个好主意(除了为我创建的每个标签创建不同的图像)

      谢谢, 盖

1 个答案:

答案 0 :(得分:0)

谢谢朋友们,

我从pinkfloydx33

中找到了我的问题的完美答案

我为我正在创建的jpeg创建了一个FileStream,将其打开为“只读”,一旦完成将它放在PrintDocument类上,我就可以很容易地覆盖/删除它。

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

       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 .....

再次感谢。

相关问题