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

Asked

Viewed 135 times

0

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

Process cannot access 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 time in the loop, but I have a new error:

Generic error of GDI+

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

1 answer

0

To make this work, you need to convert the image to a memoryStream Follows 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.