Can';t在VB.NET中打印后删除aBarcode图像(KeepAutomation)

Can';t在VB.NET中打印后删除aBarcode图像(KeepAutomation),vb.net,Vb.net,我正在建立一个标签打印机与代码128条码与KeepAutomation 在这个过程中,我实际上: 使用KeepAutomation引用模块将数据编码为条形码 Private Sub MakeImage() Dim barcode As KeepAutomation.Barcode.Bean.BarCode = New KeepAutomation.Barcode.Bean.BarCode barcode.Symbology = KeepAutomation.Barcode.Symbology.C

我正在建立一个标签打印机与代码128条码与KeepAutomation

在这个过程中,我实际上:

  • 使用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)                 
    
  • 从编码数据创建Jpeg图像(使用静态名称在硬盘上的特定位置)

  • 将图像放在打印文档中

  • 打印出来

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

    我试过:

  • 处理PrintDocument类

  • 处理、关闭和重新打开窗体本身

  • 以上这些对我都没有帮助

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

    谢谢, 盖伊

    谢谢朋友们

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

    我已经为我正在创建的jpeg创建了一个文件流,以“只读”方式打开它,一旦将其放置在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方式访问文件并以只读方式打开


    再次感谢。

    条形码是一次性的吗?不,也找过了,找不到任何处理方法。什么是文件?它是一个字符串还是一个streamFileToUse是一个简单的字符串,包含指向文件夹中applicationIn的相对路径:“.\FileName.jpg”这可能导致锁定<代码>条形码。generateBarcodeToImageFile(FileToUse)您可以在临时文件夹中创建一个带有随机文件名的临时文件,创建文件后,将其复制到FileToUse。然后,当应用程序打开时,清除tempoary文件夹。因为您无法更改KeepAutomation API