Image files

Gazzo
10-04-2001, 11:27 AM
Hi can anybody help please,

I am working on a file upload component for an ASP page, I have this working with only one problem, and that is when I upload a jpg, bmp or gif file. The data that I am working with is stored in unicode format and I want to write it to a file.

I am having problems with this and as my server is in the next room, and everytime I make a change to the component dll I have to go next door and stop the services, re-register it etc.

Therefore I have decided to get this part working in a simple VB program first. I tried doing the following but with no success:

Private Sub cmd_Read_Click()
Dim hfile As Long
Dim x As Variant
Dim i As Long

hfile = FreeFile
Open txtFile For Binary Access Read As hfile
hfile2 = FreeFile
Open "C:\TestData.jpg" For Binary Access Write As hfile2

Do Until EOF(hfile)
i = i + 1
Get hfile, i, x
Put hfile2, i, x
Loop

Close hfile
Close hfile2

End Sub

It successfully creates a testdata.jpg file but the data is not the same as in the original file therefore is cannot recognise it as a jpg.

Can anyone tell me how to copy a jpg file byte by byte into a newly created file, which can then be opened as a jpg.

Thanks,
Gazzo.

Thinker
10-04-2001, 11:34 AM
The problem is you have declared x as a Variant. A Variant is not a type
of its own, but a holder of any of the other types. This is basically making
x a String and all Strings in VB go through the unicode conversion. Try
declaring x as a Byte.

I think therefore I am... sometimes right. images/icons/wink.gif

Gazzo
10-04-2001, 11:39 AM
I tried putting x as a byte but I still got the same problem, claiming in PhotoEditor for example 'Can't determine type'.

Any other ideas?

Cheers.

ChiefRedBull
10-04-2001, 11:40 AM
Take out all instances of
<font color=red>i</font color=red>
The get statement will only read a byte if <font color=red>x</font color=red> is one byte long, and since you haven't declared this - its reading a bigger string. This then gets confused with the place counter.
so replace this:
<pre><font color=red>Do Until EOF(hfile)
i = i + 1
Get hfile, i, x
Put hfile2, i, x
Loop

</pre></font color=red>
with this
<pre><font color=red>Do Until EOF(hfile)
Get hfile, , x
Put hfile2, , x
Loop

</pre></font color=red>

Chief


"How are we to learn, if those that know will not teach... ?" - Me.

Gazzo
10-04-2001, 11:45 AM
The problem with that though is that it won't step through the file.

Cheers.

Thinker
10-04-2001, 11:53 AM
One more thing that might have an effect. I believe the first byte in a
file is 0, you are starting with 1. Either start with i = -1 or increment i
after the get. I am not sure why you can't do it Chief's way too. If x is
a byte, it should know to get exactly one byte and move the internal
pointer.

I think therefore I am... sometimes right. images/icons/wink.gif

Gazzo
10-04-2001, 11:56 AM
If I try to read byte 0 from a file it claims that it is a bad record number, heh, I thought that this would be easy.

Cheers.

ChiefRedBull
10-04-2001, 12:00 PM
I'm not sure why mine wont work either - it does for me....

Chief

"How are we to learn, if those that know will not teach... ?" - Me.

Gazzo
10-04-2001, 12:02 PM
Ok, nobody ever help me again, I have just discovered the problem, changing x to a byte works, my problem was the file I was copying was called Tiles.jpeg...............not Tiles.jpg as I was calling it.

Thanks Thinker and Chief and please accept my apologies for wasting your time. I think it is time to knock off for today.

Thanks,
Gazzo.

Thinker
10-04-2001, 12:06 PM
Yeah, I am wrong about the 0, the first byte is 1. Really, Chief's code
should work great.

Glad you figured it out - I posted before I saw your response.


I think therefore I am... sometimes right. images/icons/wink.gif<P ID="edit"><FONT class="small"><EM>Edited by Thinker on 10/04/01 01:08 PM.</EM></FONT></P>

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum