For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > December 2005 > How to assign array to a PictureBox ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to assign array to a PictureBox ?
Boki

2005-12-14, 3:55 am

Hi All,
I have a raw data arry ( byte ), now I want to assign it to a
PictureBox, and then I can control it by bitblt / stretch.. etc.

Could you please advice how to assign it to PictureBox?

Thanks a lot!

Best regards,
Boki.


J French

2005-12-14, 7:55 am

On Wed, 14 Dec 2005 15:41:28 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote:

>Hi All,
> I have a raw data arry ( byte ), now I want to assign it to a
>PictureBox, and then I can control it by bitblt / stretch.. etc.
>
>Could you please advice how to assign it to PictureBox?


For now just save your Byte Array containing the JPG to a file and use
LoadPicture
Boki

2005-12-14, 7:55 am

But it will cost a lot of time, isn't it ?

Don't we have other method ? because it is streaming data (JPG) from
Bluetooth Serial Port ... ><!!


Best regards,
Boki.

"J French" <erewhon@nowhere.uk> 撰寫於郵件新聞:43a00742.438733060@news.btopenworld.com...
> On Wed, 14 Dec 2005 15:41:28 +0800, "Boki" <bokiteam@ms21.hinet.net>
> wrote:
>
>
> For now just save your Byte Array containing the JPG to a file and use
> LoadPicture



Rob

2005-12-14, 6:57 pm

On Wed, 14 Dec 2005 20:11:52 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote:

>But it will cost a lot of time, isn't it ?
>
>Don't we have other method ? because it is streaming data (JPG) from
>Bluetooth Serial Port ... ><!!
>
>
>Best regards,
>Boki.
>
>"J French" <erewhon@nowhere.uk> 撰寫於郵件新聞:43a00742.438733060@news.btopenworld.com...
>


Try this. (I can't remember where I got it from but it seems to work)

Private Declare Function CreateStreamOnHGlobal Lib "ole32" _
(ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, _
ppstm As Any) As Long

Private Declare Function OleLoadPicture Lib "olepro32" _
(pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, _
riid As Any, ppvObj As Any) As Long

Private Declare Function CLSIDFromString Lib "ole32" _
(ByVal lpsz As Any, pclsid As Any) As Long

Private Declare Function GlobalAlloc Lib "kernel32" _
(ByVal uFlags As Long, ByVal dwBytes As Long) As Long

Private Declare Function GlobalLock Lib "kernel32" _
(ByVal hMem As Long) As Long

Private Declare Function GlobalUnlock Lib "kernel32" _
(ByVal hMem As Long) As Long

Public Function PictureFromByteStream(b() As Byte) As IPicture
Dim LowerBound As Long
Dim ByteCount As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture(15)
Dim istm As stdole.IUnknown

On Error GoTo Err_Init
If UBound(b, 1) < 0 Then
Exit Function
End If

LowerBound = LBound(b)
ByteCount = (UBound(b) - LowerBound) + 1
hMem = GlobalAlloc(&H2, ByteCount)
If hMem <> 0 Then
lpMem = GlobalLock(hMem)
If lpMem <> 0 Then
CopyMemory ByVal lpMem, b(LowerBound), ByteCount
GlobalUnlock hMem
If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then
If
CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"),
IID_IPicture(0)) = 0 Then
OleLoadPicture ByVal ObjPtr(istm), ByteCount, 0,
IID_IPicture(0), PictureFromByteStream
End If
End If
End If
End If

Exit Function

Err_Init:
If Err.Number = 9 Then
'Uninitialized array
MsgBox "You must pass a non-empty byte array to this function!"
Else
MsgBox Err.Number & " - " & Err.Description
End If
End Function
Karl E. Peterson

2005-12-14, 6:57 pm

Boki wrote:
> Hi All,
> I have a raw data arry ( byte ), now I want to assign it
> to a PictureBox, and then I can control it by bitblt / stretch.. etc.
>
> Could you please advice how to assign it to PictureBox?


Funny, I just answered this last w...

http://groups.google.com/group/micr...d450059ddd5bc49
--
Working without a .NET?
http://classicvb.org/


Karl E. Peterson

2005-12-14, 6:57 pm

Rob wrote:
> Try this. (I can't remember where I got it from but it seems to work)


Wow, that's just way easier than the way I was using. Googled around, and
found it on a number of sites, some of which point here as the source:

http://www.planet-source-code.com/v...=29004&lngWId=1

Cool...
--
Working without a .NET?
http://classicvb.org/


Karl E. Peterson

2005-12-14, 6:57 pm

Karl E. Peterson wrote:
> Rob wrote:
>
> Wow, that's just way easier than the way I was using. Googled
> around, and found it on a number of sites, some of which point here
> as the source:
>
>

http://www.planet-source-code.com/v...=29004&lngWId=1
>
> Cool...


Actually, shoulda known(!), a bit more tracing back and we find this code
originated with Brad Martinez. The PSC "contributor" did his best to make
it ugly, unreadable, and basically unfathomable, but it's apparently stolen
nonetheless.

http://www.experts-exchange.com/Pro...Q_20144407.html

Jeez, I hate PSC...
--
Working without a .NET?
http://classicvb.org/


Boki

2005-12-14, 9:55 pm

It is professional!

Thanks! :D

Best regards,
Boki.

"Rob" <rob@notvalid.com>
???????:fpp0q1dt8es9vna3dt1l0ginmgj3oam1g3@4ax.com...
> On Wed, 14 Dec 2005 20:11:52 +0800, "Boki" <bokiteam@ms21.hinet.net>
> wrote:
>
>
> Try this. (I can't remember where I got it from but it seems to work)
>
> Private Declare Function CreateStreamOnHGlobal Lib "ole32" _
> (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, _
> ppstm As Any) As Long
>
> Private Declare Function OleLoadPicture Lib "olepro32" _
> (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, _
> riid As Any, ppvObj As Any) As Long
>
> Private Declare Function CLSIDFromString Lib "ole32" _
> (ByVal lpsz As Any, pclsid As Any) As Long
>
> Private Declare Function GlobalAlloc Lib "kernel32" _
> (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
>
> Private Declare Function GlobalLock Lib "kernel32" _
> (ByVal hMem As Long) As Long
>
> Private Declare Function GlobalUnlock Lib "kernel32" _
> (ByVal hMem As Long) As Long
>
> Public Function PictureFromByteStream(b() As Byte) As IPicture
> Dim LowerBound As Long
> Dim ByteCount As Long
> Dim hMem As Long
> Dim lpMem As Long
> Dim IID_IPicture(15)
> Dim istm As stdole.IUnknown
>
> On Error GoTo Err_Init
> If UBound(b, 1) < 0 Then
> Exit Function
> End If
>
> LowerBound = LBound(b)
> ByteCount = (UBound(b) - LowerBound) + 1
> hMem = GlobalAlloc(&H2, ByteCount)
> If hMem <> 0 Then
> lpMem = GlobalLock(hMem)
> If lpMem <> 0 Then
> CopyMemory ByVal lpMem, b(LowerBound), ByteCount
> GlobalUnlock hMem
> If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then
> If
> CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"),
> IID_IPicture(0)) = 0 Then
> OleLoadPicture ByVal ObjPtr(istm), ByteCount, 0,
> IID_IPicture(0), PictureFromByteStream
> End If
> End If
> End If
> End If
>
> Exit Function
>
> Err_Init:
> If Err.Number = 9 Then
> 'Uninitialized array
> MsgBox "You must pass a non-empty byte array to this function!"
> Else
> MsgBox Err.Number & " - " & Err.Description
> End If
> End Function



Boki

2005-12-14, 9:55 pm

Thanks for the code :D

Best regards,
Boki.

"Karl E. Peterson" <karl@mvps.org> 撰寫於郵件新聞:eXZTpIOAGHA.360@TK2MSFTNGP09.phx.gbl...
> Rob wrote:
>
> Wow, that's just way easier than the way I was using. Googled around, and
> found it on a number of sites, some of which point here as the source:
>
> http://www.planet-source-code.com/v...=29004&lngWId=1
>
> Cool...
> --
> Working without a .NET?
> http://classicvb.org/
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com