|
-
Dec 28th, 2002, 11:24 PM
#1
Thread Starter
Lively Member
Picture to Array, Array to Picture
OK I AM GETTING SO ANNOYED OVER THIS PROBLEM, ALL I WANT TO DO IS SEND A JPG OVER WINSOCK AND I CANT FIGURE OUT HOW TO DO IT
I know I have to change the picture into a byte array to send it and then change it back, BUT WHAT IS THE CODE FOR THIS????
I've been posting on these messageboards for 4 days with no Good response to this answer, Does anyone know the code or function to do this
Thanks,
Justin
-
Dec 29th, 2002, 12:59 AM
#2
Good Ol' Platypus
To make it easy on yourself, I would simply send 'packets'. Send 1024 bytes at a time, by appending the characters to each other in a STRING (ex. String = Chr(0) & Chr(1) & Chr(2), but programatically). Next, use Winsock1.Send String, vbString (I've don't use winsock that often so it might not need the vbString). Then, on the other side, when you get the packets, start writing them to a file.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 30th, 2002, 10:52 AM
#3
Frenzied Member
Huh and what would happen when you encontered a null character, hmm? 
You just get a byte array from the image and send it, there's a function for that. I already gave you the code... ok, here it is, just copy and paste:
VB Code:
Declarations:
Private Type SAFEARRAYBOUND
cElements As Long
lLbound As Long
End Type
Private Type SAFEARRAY1D
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
Bounds(0 To 0) As SAFEARRAYBOUND
End Type
Private Type SAFEARRAY2D
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
Bounds(0 To 1) As SAFEARRAYBOUND
End Type
Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
'To get an array from the image:
' these are used to address the pixel using matrices
Dim pict() As Byte
Dim sa As SAFEARRAY2D, bmp As BITMAP
' get bitmap info
GetObjectAPI Pictbox.Picture, Len(bmp), bmp
' exit if not a supported bitmap
If bmp.bmBitsPixel <> 24 Then
MsgBox " 24-bit bitmaps only", vbCritical
Exit Sub
End If
' have the local matrix point to bitmap pixels
With sa
.cbElements = 1
.cDims = 2
.Bounds(0).lLbound = 0
.Bounds(0).cElements = bmp.bmHeight
.Bounds(1).lLbound = 0
.Bounds(1).cElements = bmp.bmWidthBytes
.pvData = bmp.bmBits
End With
CopyMemory ByVal VarPtrArray(pict), VarPtr(sa), 4
'To put it back and clean up:
' clear the temporary array descriptor
' without destroying the local temporary array
CopyMemory ByVal VarPtrArray(pict), 0&, 4
Hope that helps
-
Dec 30th, 2002, 12:12 PM
#4
Good Ol' Platypus
So, you're telling him to send an uncompressed bitmap?
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 30th, 2002, 12:15 PM
#5
Frenzied Member
-
Dec 30th, 2002, 01:37 PM
#6
Thread Starter
Lively Member
Thanks
-
Dec 30th, 2002, 09:48 PM
#7
-
Dec 30th, 2002, 10:46 PM
#8
Good Ol' Platypus
Your way would've worked well for LAN situations.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 30th, 2002, 11:00 PM
#9
Frenzied Member
Yes, you're right, but usually Winsock is used for internet connections... (writing and reading the file would have taken much longer, right?)
-
Jan 10th, 2003, 10:16 PM
#10
Junior Member
I have a question regarding GetObjectAPI. Can you use it on any StdPicture object to get the image data? Also, is there a way to do it in reverse - i.e. a SetObjectAPI function? That would be quite useful to me.
Also, could these methods be used on a D3D texture object, or is there another method that one has to use?
-
Jan 10th, 2003, 11:37 PM
#11
Good Ol' Platypus
You can use SelectObject, I believe.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jan 11th, 2003, 08:20 AM
#12
Ex-Super Mod'rater
I think I should point this out that in the code given above by Jotaf98 he's missed off this line,as most example of this method do:
VB Code:
Private Declare Function VarPtr Lib "msvbvm50.dll" (Ptr As Any) As Long
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Jan 11th, 2003, 12:19 PM
#13
Good Ol' Platypus
VarPtr is standard VB syntax. VarPtrArray isn't.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jan 11th, 2003, 01:32 PM
#14
Using SAFEARRAY in VB, it's paradox...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 11th, 2003, 01:54 PM
#15
Ex-Super Mod'rater
Saxtraxi i'm not saying replace the API with the one I gave, I'm saying you need it aswel because in the following line its called twice, one passes an array and one passes a non-array
VB Code:
CopyMemory ByVal VarPtrArray(pict), VarPtr(sa), 4
It thro's up errors without the "VarPtr" being declared.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|