Error inserting image loop in report pdf reports.dll .net

0

I have a while that will repeat 3 times an insertion of a barcode however I am using lib reports.dll to create the pdf report. This lib accepts only images saved in some directory (as far as I know), but at the moment I'm going to insert the image already created it returns an error:

  

The process can not access the file 'C: \ cod.jpeg' because it is   being used by another process

Dim Chave = "858300000009330003101607570100361164044015053000"
Dim barcode As New BarcodeLib.Barcode()
Dim img As Bitmap = barcode.Encode(BarcodeLib.TYPE.CODE128C, Chave)
img.Save("C:\cod.jpeg", Imaging.ImageFormat.Jpeg)

linhaPreencheCont = 15

Dim i As Integer = 0
While i < 3

PDFPage.Add(35, linhaPreencheCont, New RepImage("C:\cod.jpeg", 300, 40))

linhaPreencheCont +=60
end while

I have also tried to create a new bitmap object every lap in the loop, but I have a new error:

  

Generic GDI + error

Dim Chave = "858300000009330003101607570100361164044015053000"
Dim barcode As New BarcodeLib.Barcode()


dim linhaPreencheCont as integer = 15
Dim i As Integer = 0

While i < 3

Dim img As Bitmap = New Bitmap(barcode.Encode(BarcodeLib.TYPE.CODE128C, Chave))
img.Save("C:\cod.jpeg", Imaging.ImageFormat.Jpeg)

PDFPage.Add(35, linhaPreencheCont, New RepImage("C:\cod.jpeg", 300, 40))

linhaPreencheCont +=60
end while
    
asked by anonymous 03.03.2016 / 13:49

1 answer

0

For this to work, you need to convert the image to a memoryStream Here is the code:

Dim Chave = "858300000009330003101607570100361164044015053000"
Dim barcode As New BarcodeLib.Barcode()
Dim img As Bitmap = barcode.Encode(BarcodeLib.TYPE.CODE128C, Chave)
img.Save("C:\cod.jpeg", Imaging.ImageFormat.Jpeg)

linhaPreencheCont = 15

Dim i As Integer = 0
While i < 3
  Dim fileImg As Byte() = IO.File.ReadAllBytes("C:\cod.jpeg")
  Dim memory As New MemoryStream(fileImg)

PDFPage.Add(35, linhaPreencheCont, New RepImage(memory , 300, 40))

linhaPreencheCont +=60
end while
    
03.03.2016 / 17:26