Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save picture to a byte array 1

Status
Not open for further replies.

BogdanMBM

Programmer
Aug 6, 2003
213
RO
Hie!

How can I save a picture into a byte array and then read from that byte array in order to fill another picturebox?

Thanks.

Hope I've been helpful,
Bogdan Muresan.
 
Yes. And probably the easiest way is to investigate the fact that StdPicture is persistable (It is certainly the technique I use to quickly and easily send picture objects from one computer to another via winsock without having to write any protocol handling of my own)
 
Wow! That's exactly what I'm (desperately) looking for! To send a picture between 2 computers using winsock.
But how do yuo manage that? I mean it's not working just to:
Private iPicture as StdPicture
...
WS1.SendData iPicture

and on the client side

iPicture2 = WS2.GetData ?

Hope I've been helpful,
Bogdan Muresan.
 
I have previously provided a more-or-less full working solution to this in this forum. Hang on...<fx: tappety, tappety> here you go: thread222-557000
 
Thanks very much, strongm!
I'll trie it! Looks simple and it seems to be just what I was looking for: a simple solution to do the job.
Before this I was traying with DIB and, oh ... it was a pain 'cause I'm not that familiar wit this immage processing techniques.
Thanks again!



Hope I've been helpful,
Bogdan Muresan.
 
stronfm,

Bad news:
I've tried your code from Thread222-557000, but it doesn't work. To be more exact, at line "pb.Contents = buffer" from event procedure "Winsock2_DataArrival" a get the error message: "Invalid procedure call or argument."
Why is that? What I am missing here?

Thanks.
 
The code is an illustration rather than a rigorous solution. Your error is being caused by the fact that the initial data arrival event does not actually transfer the entire propertybag. Indeed, it may take several data arrivals to fully transfer it.
 
'morning! (for me it is :) )

And a possible solution would be something like that:
On "SendComplete" event of the sender to send another message to the client, let's say a vbCrlf; while on the client side, before reading into pb.Contents:
Winsock2.GetData buffer, , MyVar
if not MyVar = vbcrlf then
pb.Contents = buffer
else
Set Picture2.Picture = pb.ReadProperty("SentStdPicture", 0)
endif

I think that should work... I'll trie that and let you all know.
Thanks.
 
I finaly made it!
Here's my solution:

On the server side:

Private Sub Command1_Click()
Dim pb As PropertyBag
Set pb = New PropertyBag
pb.WriteProperty "SentStdPicture", Image1.Picture, 0
Winsock1.SendData pb.Contents
End Sub

Private Sub Form_Load()
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub

On the client side:

Dim pb As PropertyBag
Dim Buffer() As Byte, Storage() As Byte
Dim Nr As Integer

Private Sub Command1_Click()
Image2.Picture = LoadPicture
End Sub

Private Sub Form_Load()
Winsock2.Connect
ReDim Preserve Storage(0)
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Set pb = New PropertyBag
Winsock2.GetData Buffer, vbByte + vbArray, bytesTotal
OldUBoundStorage = IIf(UBound(Storage) = 0, 0, UBound(Storage))
ReDim Preserve Storage(UBound(Storage) + UBound(Buffer) + 1)
For x = 0 To UBound(Buffer)
Storage(x + OldUBoundStorage) = Buffer(x)
Next
On Error GoTo e:
pb.Contents = Storage
Set Image2.Picture = pb.ReadProperty("SentStdPicture", 0)
ReDim Storage(0)
e:
End Sub

strongm, thanks for the initial hint!
Here's a star for you. Well, I should probably award one to myself to!

Hope I've been helpful,
Bogdan Muresan.
 
Some comments regarding my own code:

1.) Disregard "OldUBoundStorage = IIf(UBound(Storage) = 0, 0, UBound(Storage))" It should be just "OldUBoundStorage = IIf(UBound(Storage)"
2.) Disregard "Dim Nr As Integer" It is never used...
3.) Disregard
"Private Sub Command1_Click()
Image2.Picture = LoadPicture
End Sub" It is of no use for the subject.
4.) Does anyone know how to concatenate 2 byte arrays faster then I did?
Thankc.

Hope I've been helpful,
Bogdan Muresan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top