OK, here's the problem. I'm trying to read a data file, and read it byte by byte and write it into a .gif file, here's my code:
Now, this is a function that should work for any of my data files that i give it, but if i run the function more than once, it says "C:\Temp\temp.gif" is being used by another process or something. Also sometimes when I only use the function once, it stops at Kill("C:\Temp\temp.gif") and says the same thing. I don't get it, I'm closing everything.
VB.NET:
[size=2][color=#0000ff]Public [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] DecodePicture([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] filename [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]String[/color][/size][size=2]) [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] s1, s2 [/size][size=2][color=#0000ff]As[/color][/size][size=2] FileStream[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] br [/size][size=2][color=#0000ff]As[/color][/size][size=2] BinaryReader[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] bw [/size][size=2][color=#0000ff]As[/color][/size][size=2] BinaryWriter[/size]
[size=2]s1 = [/size][size=2][color=#0000ff]New[/color][/size][size=2] FileStream(filename, FileMode.Open, FileAccess.Read)[/size]
[size=2]s2 = [/size][size=2][color=#0000ff]New[/color][/size][size=2] FileStream("C:\Temp\temp.gif", FileMode.Create, FileAccess.Write)[/size]
[size=2]br = [/size][size=2][color=#0000ff]New[/color][/size][size=2] BinaryReader(s1)[/size]
[size=2]bw = [/size][size=2][color=#0000ff]New[/color][/size][size=2] BinaryWriter(s2)[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] y [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer[/color][/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] byteread [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Byte[/color][/size]
[size=2][color=#0000ff]For[/color][/size][size=2] y = 0 [/size][size=2][color=#0000ff]To[/color][/size][size=2] br.BaseStream.Length() - 1[/size]
[size=2] byteread = br.ReadByte
bw.Write(byteread)
[/size][size=2][color=#0000ff]Next[/color][/size]
[size=2]br.Close()
bw.Close()
s1.Close()
s2.Close()
br = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2]bw = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2]s1 = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2]s2 = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] temp [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap = Image.FromFile("C:\Temp\temp.gif")[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] decoded [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Bitmap(temp)[/size]
[size=2]temp = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2]Kill("C:\Temp\temp.gif")
[/size][size=2][color=#0000ff]Return[/color][/size][size=2] decoded[/size]
[size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Function
[/color][/size]
Now, this is a function that should work for any of my data files that i give it, but if i run the function more than once, it says "C:\Temp\temp.gif" is being used by another process or something. Also sometimes when I only use the function once, it stops at Kill("C:\Temp\temp.gif") and says the same thing. I don't get it, I'm closing everything.
Last edited: