Results 1 to 10 of 10

Thread: Putting a picture into a string and resizing.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    28

    Question Putting a picture into a string and resizing.

    Hello

    I want to capture the screen, then resize the image and then put it into a string (because i must send the picture through winsock to another pc)

    I can capture the screen.
    But by resizing and putting it into a string i'm having troubles.
    I've got already a little bit code but the function StretchBlt won't put data into the variable "HdcOut".

    Code:
    '//api
    Declare Function GetDesktopWindow Lib "user32" () As Long
    Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    
    '//code
    Public Sub GetDesktop()
    Dim dhandle As Long
    Dim HdcOut As Long
    dhandle = GetDesktopWindow
    Dim ddc As Long
    ddc = GetDC(dhandle)
    
    StretchBlt HdcOut, 0, 0, 640, 480, ddc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, vbSrcCopy
     
    End Sub
    thanks!!

  2. #2
    hellswraith
    Guest
    I think your going to have to use a byte array to send the data, you can't put a picture in a string.....at least I don't think you can...

  3. #3
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Originally posted by hellswraith
    I think your going to have to use a byte array to send the data, you can't put a picture in a string.....at least I don't think you can...
    You can if you convert the bytes to ASCII characters.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4
    Addicted Member chander's Avatar
    Join Date
    Nov 2000
    Location
    New Delhi , India
    Posts
    225
    hey any one of u can tell abt how to convert a picture from picture box to Byte array .. i want to send these byte array data to another PC .. any one suggest on this ??
    Chander
    Email:[email protected]

  5. #5
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    same prob

    hey,

    i got the same prob as this, i have always needed to send a picture using winsock, WITHOUT SAVING THE PIC TO FILE.

    but, I havnt been able to.

    There is also the prob about size too.

    If i knew how you could change a picture into a string, that wud be fantastic. Would also help if there is a way to reduce its quality/size too, to make it transfer quicker!

    This is just wat i need, aswell as the thread starter, why hasnt anyone go further with this thread?

    I would also appreciate any responses to this!

    Thanks,

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Have a look at this site
    It has some sample code to convert a picture to and from a byte array.

  7. #7
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    thanks

    thanks frans c, looks like a good website, ill take a look in a min and tell ya what i think and if it helps,

    thanks in advanced


    1 min lata (edited)
    looks good, thanks for the code, ill try the code lata in my prog

  8. #8
    Addicted Member chander's Avatar
    Join Date
    Nov 2000
    Location
    New Delhi , India
    Posts
    225
    surely its good code to convert pictures , but how u r going to transfer it on winsock .. i think data transmits in form of string on winsock .. how can we transmit byte array ?

    one more way to convert picture data in strings through Serialization .. i m not much sure of it but i m working on it , and also i hv to check if after serialization i could unserialize to get it back in picture object or any other format from which it was converted .. hopefuly if i suceed i will let u know ...
    Chander
    Email:[email protected]

  9. #9
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    that code is way too advanced for what i need, and it doesnt work anyway, not for what i want anyway!

    and yea, how are u supposed to transfer a byte array? didnt we say about strings, not byte arrays. peeps today dont listen

  10. #10
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Winsock has no problem with byte arrays (just press F1 on SendData), and converting a byte array to a string is so easy, that I assumed it was common knowledge.

    MyString = MyByteArray

    Or if like your strings in unicode (will double the size though):

    MyString = StrConv(MyByteArray, vbUnicode)

    If you don't like advanced code, just save it to a file first, and then read it back in a string.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width