If drPhoto.HasRows = True Then
While (drPhoto.Read() = True)
Dim i As Integer
For i = 0 To drPhoto.FieldCount - 1
If i = 0 Then
Dim texta As String = Convert.ToString(drPhoto.GetValue(i))
End If
If i = 1 Then
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream()
Dim binData() As System.Byte = CType(drPhoto.GetValue(i), System.Byte())
MS.Write(binData, 0, binData.Length)
imagesrc = System.Drawing.Image.FromStream(MS)
If System.IO.File.Exists(ImagePath & "\imagesrc.bmp") = True Then
System.IO.File.Delete(ImagePath & "\imagesrc.bmp")
imagesrc.Save(ImagePath & "\imagesrc.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
Else
imagesrc.Save(ImagePath & "\imagesrc.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
End If
End If
Next
End While
Else
ptbEMPPhoto.Image = System.Drawing.Image.FromFile(ImagePath & "\noimage.bmp")
Exit Sub
End If
Dim imgOrg As Bitmap
Dim imgShow As Bitmap
Dim g As Graphics
Dim divideBy, divideByH, divideByW As Double
imgOrg = DirectCast(Bitmap.FromFile(ImagePath & "\imagesrc.bmp"), Bitmap)
divideByW = imgOrg.Width / ptbEMPPhoto.Width
divideByH = imgOrg.Height / ptbEMPPhoto.Height
If divideByW > 1 Or divideByH > 1 Then
If divideByW > divideByH Then
divideBy = divideByW
Else
divideBy = divideByH
End If
imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy))
imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
Else
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
End If
ptbEMPPhoto.Image = imgShow
in the code where the image is going to be deleted i get the message "being used by another process" how can close the file so that i may delete it?