image through stream

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
Thanks John, I am trying to send this image in through a tcp stream, like you showed me earlier. It is all working awesome, but I thought I could make the images smaller to speed things up 9because it is going to a handheld device). With the example you showed me, you were writting to the tcp stream by reading a buffer from a filestream. So, what do you think is the best way to do the exact same setup with decreasing image sizes? Let's say I know the path of the image, and I want to decrease it's size before I send it. I could not use the compression namespace because CF does not have it.
 
You can use the Save method to "save" to the stream. (thumb.Save(tcp.GetStream, ImageFormat.Jpeg)
 
That is cool, the only problem is my client is not reading it. How would I open an image that has been saved to the stream? This is what I was using, and it does not work:


VB.NET:
 Dim buffer(8092) As Byte, readstotal As Long = 0
        Dim reads As Integer = -1
        'using filestream to write read filebytes directly from networkstream
        Using fs As New IO.FileStream(filepath, IO.FileMode.Create, IO.FileAccess.Write)
            Do Until readstotal = filelen
                reads = clientSocket.GetStream.Read(buffer, 0, buffer.Length)
                fs.Write(buffer, 0, reads)
                readstotal += reads
            Loop
        End Using
 
VB.NET:
Image.FromStream(tcp.GetStream).Save(filename)
(I splitted thread, since this stuff only regards the tcp communication.)
 
I am just having bad luck.CF does not support image.fromstream...so, I am going to have to use the old filestream I was using before, I think. one thing I tried was creating the thunb bitmap from the filestream and then saving it to a memorystream...but the client would throw the "not expected value" error when trying to convert the bytes to the bitmap. I suppose I could make a temporary thumb file and then open it from the filestream with my existing code..but it seems redundent. do you know anything else?
 
Last edited:
The code you have in post 3 should be reading it, it works fine here, but when the receiver is not using the FromStream method he will have to know the length of the image stream data. Did you forget to send this?
 
The code you have in post 3 should be reading it, it works fine here, but when the receiver is not using the FromStream method he will have to know the length of the image stream data. Did you forget to send this?

ok, I was using the bmp format, and for some reason it works perfect now that I changed to jpeg format. it works great. thanks.. it is tough posting from my phone..I am ata convension.
 
Back
Top