07-02-2002, 09:18 AM
I have an activex control placed on a web page. The control has a picturebox control and picture property to place a picture on it. I want to change the image in the control dynamically from the image files in the server. Could you pls. help me doing it.
07-02-2002, 10:38 AM
If you put a Winsock control on the ActiveX control, you could download the image via HTTP and save it to the local (client) hard drive, then open it in the picturebox.
That's the only way I can think of doing it really....
07-04-2002, 09:15 AM
Could you pls. give sample codes to receive image file with Winsock control, say upon clicking a button in the control
07-04-2002, 10:05 AM
Well..... you would request the file like this:
Winsock1.SendData "GET www.server.com/folder/image.jpg HTTP/1.1" & vbCrLf & vbCrLf
Then you'd receive the data in the Winsock_DataArrival() event.
07-05-2002, 08:32 AM
It seems it should work, but still I got one problem. I got data in DataArrival() event. I tried with following code:
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim data() As Byte
Winsock.GetData data, vbArray + vbByte
picImage.Picture = LoadPicture("c:\temp\pictemp")
Public Sub ImageWrite(ByVal imgdata)
Dim image() As Byte
DataFile = FreeFile()
Open "c:\temp\pictemp" For Binary Access Write As DataFile
image() = imgdata
Put DataFile, , image
... When the line=> picImage.Picture = LoadPicture("c:\temp\pictemp")
gets executed, it gives error message as "Invalid Picture". It seems the file is not saved in the proper format. I even tried to open the file from image editors but couldn't. How can it be saved in proper format.
I hope your next reply will give the solution to the problem
07-05-2002, 12:56 PM
The reason being that when you make an HTTP request, the HTTP server will send back an HTTP header response - this is not part of the image. You need to strip off the HTTP header whcih looks something like this:
HTTP 200 OK
The easiest way to do this is to simply search the incoming string for the first instance of a double vbCrLf then ignore everything before it.
07-07-2002, 07:33 AM
In order to strip off header part, I need to get the data in string format. With Winsock.Getdata data, vbString statement I got the position of double vbCrLf but the remaining image data also became string which should be in bytearray to get the image. If the data is retrieved like Winsock.Getdata data, vbArray+vbByte ; the whole data will be in byte array and I couldn't get double vbCrLf position to strip off the header.
In this situation, how can I get header data separated with image data in proper format? Could you pls. try it out and get back with the successful code. I'd appreciate your effort for solving my problem.
07-07-2002, 08:06 AM
Well, you can receive the data in string format - it won't corrupt it at all since a string is simply a collection of ascii chraracters, the same as a byte array.
Or, you can convert the bytearray to a string using the StrConv() function.
07-07-2002, 08:35 AM
Yeah, I tried with the second option and works well. Now I could see the image saved but partially. It seems, partial data arrived with DataArrival event of the Winsock control. Do I need to go on appending data in this event? If so, when can I know that complete data is arrived so that I can write complete image data?
07-07-2002, 09:55 AM
You will know when all the data is arrived when the connection closes. This is standard HTTP practice - the header is transmitted, then the file, then the connection closes. Look for the Winsock_Close event (if you're using Winsock).
07-08-2002, 07:25 AM
Thanks. It works. This is loading part.
I wanna manipulate the loaded image in the activex control and write back to the server. Is there any easy way for writing back to the server?
07-08-2002, 10:28 AM
I can think of a few ways - the first would be to use HTTP again, and submit the picture via a form to a CGI script which would upload it. This would be the least work for you because you can download free CGI scripts that will do all the hard work for you, all you have to do is post a simple form via Winsock (http://www.winsockvb.com/snippets/post1.html)
Another way is to use ADO - if you've got a database on your server that the image is being pulled from, AFAIK you can use ADO or DAO or one of the data object things to write it directly back again.. but this might be a lot of work ( I don't know, I don't work with databases ).
Lastly, there's FTP. If you have FTP access to the server ( I'll assume you do ) you can use either the Winsock or Inet controls to upload to a specific directory and filename. It's dead easy using the Inet.. only a few lines. However, it's hard to get progress reports. If you use the Winsock control, you'll have to learn some of the actual FTP protocol, but you'll be able to tell exactly how much has been sent, giving accurate progress.
07-10-2002, 07:03 AM
Thanks. I'll try it.