msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

picture and ado stream

 
Post new topic   Reply to topic    msvisual.com Forum Index -> OLE
Author Message
Meelis



Joined: 04 Oct 2007
Posts: 18

PostPosted: Sat Sep 09, 2006 3:50 pm    Post subject: picture and ado stream Reply with quote

Hi


How to save image from picturebox to ADO stream without to save it first do
disk?



WBR
Mex

Archived from group: microsoft>public>vb>controls
Back to top
View user's profile Send private message
Mike D Sutton



Joined: 04 Oct 2007
Posts: 1298

PostPosted: Sat Sep 09, 2006 3:36 pm    Post subject: Re: picture and ado stream Reply with quote

> How to save image from picturebox to ADO stream without to save it first do
> disk?

Convert the image into a PackedDIB (a memory buffer representing a picture) and dump that into your ADO stream. The DIB
article on my site covers the conversion process to and from PackedDIBs.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/
Back to top
View user's profile Send private message
Meelis



Joined: 04 Oct 2007
Posts: 18

PostPosted: Sun Sep 10, 2006 7:13 pm    Post subject: Re: picture and ado stream Reply with quote

hmm
i an create and convert packedDIB, but how to "dump" it to sream?? Sad(

shame on me Smile


Mex


"Mike D Sutton" wrote in message$0GHA.1252@TK2MSFTNGP04.phx.gbl...
> > How to save image from picturebox to ADO stream without to save it first
do
> > disk?
>
> Convert the image into a PackedDIB (a memory buffer representing a
picture) and dump that into your ADO stream. The DIB
> article on my site covers the conversion process to and from PackedDIBs.
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Back to top
View user's profile Send private message
Mike D Sutton



Joined: 04 Oct 2007
Posts: 1298

PostPosted: Sun Sep 10, 2006 7:59 pm    Post subject: Re: picture and ado stream Reply with quote

> i an create and convert packedDIB, but how to "dump" it to sream?? Sad(
> shame on me Smile

I assumed you were already familiar with how to use binary data with an ADO stream and it was the conversion from a
picture into a binary representation that was the problem. Unfortunately I have very little experience with ADO,
however from a quick hunt on Google there appears to be a Write() method on an ADO stream which accepts a data buffer
when its type is set to adTypeBinary. You'll need to lock the HGLOBAL containing the PackedDIB using GlobalLock(),
which gives you a pointer to the first byte of data for the image, then pass that to your ADO stream. Depending on how
it's implemented, you may need to copy the entire buffer locally to a byte array first (you can use GlobalSize() to get
the length of the buffer.) If this is unsatisfactory for performance reasons then you can short circuit the DIBSection
to PackedDIB routine and build a byte array instead of an HGLOBAL.
Another option would be to hijack a null byte array by re-writing its descriptor to point at the HGBLOBAL's memory; it's
a bit of a hack but should be very fast without requiring you to do much additional work (apart from managing the array
itself.) If you're interested in that technique then have a look for VarPtrArr(), however if you're not comfortable
with working with memory or 'under the hood' of VB then you may prefer one of the 'safer' alternatives above Smile
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/
Back to top
View user's profile Send private message
Meelis



Joined: 04 Oct 2007
Posts: 18

PostPosted: Sun Sep 10, 2006 10:19 pm    Post subject: Re: picture and ado stream Reply with quote

hi and thnx

i know how to work with ADO, but no glue how to work with memory or get data
from memory to bytearray Smile)


Mex





"Mike D Sutton" wrote in message
news:%23k%23cgmO1GHA.328@TK2MSFTNGP06.phx.gbl...
> > i an create and convert packedDIB, but how to "dump" it to sream?? Sad(
> > shame on me Smile
>
> I assumed you were already familiar with how to use binary data with an
ADO stream and it was the conversion from a
> picture into a binary representation that was the problem. Unfortunately
I have very little experience with ADO,
> however from a quick hunt on Google there appears to be a Write() method
on an ADO stream which accepts a data buffer
> when its type is set to adTypeBinary. You'll need to lock the HGLOBAL
containing the PackedDIB using GlobalLock(),
> which gives you a pointer to the first byte of data for the image, then
pass that to your ADO stream. Depending on how
> it's implemented, you may need to copy the entire buffer locally to a byte
array first (you can use GlobalSize() to get
> the length of the buffer.) If this is unsatisfactory for performance
reasons then you can short circuit the DIBSection
> to PackedDIB routine and build a byte array instead of an HGLOBAL.
> Another option would be to hijack a null byte array by re-writing its
descriptor to point at the HGBLOBAL's memory; it's
> a bit of a hack but should be very fast without requiring you to do much
additional work (apart from managing the array
> itself.) If you're interested in that technique then have a look for
VarPtrArr(), however if you're not comfortable
> with working with memory or 'under the hood' of VB then you may prefer one
of the 'safer' alternatives above Smile
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Back to top
View user's profile Send private message
Mike D Sutton



Joined: 04 Oct 2007
Posts: 1298

PostPosted: Sun Sep 10, 2006 9:25 pm    Post subject: Re: picture and ado stream Reply with quote

> i know how to work with ADO, but no glue how to work with memory or get data
> from memory to bytearray Smile)

You can use this as a very basic example:

'*** Warning; air code..
Private Declare Function GlobalLock Lib "Kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "Kernel32/dll" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "Kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Sub RtlMoveMemory Lib "Kernel32.dll" ( _
ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

Private Function hGlobalToByteArr( _
ByVal inHGlobal As Long, ByRef outBytes() As Byte) As Long
Dim DataPtr As Long
Dim RetArr() As Byte

' Attempt to get pointer to data
DataPtr = GlobalLock(inHGlobal)
If (DataPtr) Then ' Grab size of buffer
hGlobalToByteArr = GlobalSize(inHGlobal)

If (hGlobalToByteArr > 0) Then
' Allocate buffer and copy data locally
ReDim RetArr(0 To hGlobalToByteArr - 1) As Byte
Call RtlMoveMemory(RetArr(0), ByVal DataPtr, hGlobalToByteArr)
outBytes = RetArr() ' Return
End If

' Done with memory object
Call GlobalUnLock(inHGlobal)
End If
End Function
'***

Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/
Back to top
View user's profile Send private message
Meelis



Joined: 04 Oct 2007
Posts: 18

PostPosted: Mon Sep 11, 2006 1:09 am    Post subject: Re: picture and ado stream Reply with quote

hmmm
maybe im doing something wrong but i cant get same data to stream when i use
loadfromfile method of stream Sad


Mex


"Mike D Sutton" wrote in message@TK2MSFTNGP03.phx.gbl...
> > i know how to work with ADO, but no glue how to work with memory or get
data
> > from memory to bytearray Smile)
>
> You can use this as a very basic example:
>
> '*** Warning; air code..
> Private Declare Function GlobalLock Lib "Kernel32.dll" (ByVal hMem As
Long) As Long
> Private Declare Function GlobalSize Lib "Kernel32/dll" (ByVal hMem As
Long) As Long
> Private Declare Function GlobalFree Lib "Kernel32.dll" (ByVal hMem As
Long) As Long
> Private Declare Sub RtlMoveMemory Lib "Kernel32.dll" ( _
> ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
>
> Private Function hGlobalToByteArr( _
> ByVal inHGlobal As Long, ByRef outBytes() As Byte) As Long
> Dim DataPtr As Long
> Dim RetArr() As Byte
>
> ' Attempt to get pointer to data
> DataPtr = GlobalLock(inHGlobal)
> If (DataPtr) Then ' Grab size of buffer
> hGlobalToByteArr = GlobalSize(inHGlobal)
>
> If (hGlobalToByteArr > 0) Then
> ' Allocate buffer and copy data locally
> ReDim RetArr(0 To hGlobalToByteArr - 1) As Byte
> Call RtlMoveMemory(RetArr(0), ByVal DataPtr, hGlobalToByteArr)
> outBytes = RetArr() ' Return
> End If
>
> ' Done with memory object
> Call GlobalUnLock(inHGlobal)
> End If
> End Function
> '***
>
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Back to top
View user's profile Send private message
Mike D Sutton



Joined: 04 Oct 2007
Posts: 1298

PostPosted: Mon Sep 11, 2006 1:38 am    Post subject: Re: picture and ado stream Reply with quote

> maybe im doing something wrong but i cant get same data to stream when i use
> loadfromfile method of stream Sad

Why are you loading from a file? If you're loading the original image from a file then skip all the PackedDIB stuff and
just write the file buffer to the stream, it would be far easier and more efficient.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/
Back to top
View user's profile Send private message
Meelis Lilbok



Joined: 04 Oct 2007
Posts: 62

PostPosted: Mon Sep 11, 2006 12:51 pm    Post subject: Re: picture and ado stream Reply with quote

Nope im not loading from file
Let me explain what i need.

a) VB6 ActiveX dll, i generate image with picturebox, for my ASP
project.(image for authentication to avoid spam robots)
b) Now i dont want to save this image to disk on server
c) I want to write picturebox image "directly" to ADO Stream and then
Response.BinaryWrite to display image on my ASP page.


Mex



"Mike D Sutton" wrote in message
news:%23y1D7jR1GHA.2036@TK2MSFTNGP05.phx.gbl...
>> maybe im doing something wrong but i cant get same data to stream when i
>> use
>> loadfromfile method of stream Sad
>
> Why are you loading from a file? If you're loading the original image
> from a file then skip all the PackedDIB stuff and just write the file
> buffer to the stream, it would be far easier and more efficient.
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: Http://EDais.mvps.org/
>
Back to top
View user's profile Send private message
Mike D Sutton



Joined: 04 Oct 2007
Posts: 1298

PostPosted: Mon Sep 11, 2006 3:57 pm    Post subject: Re: picture and ado stream Reply with quote

> Nope im not loading from file
> Let me explain what i need.
>
> a) VB6 ActiveX dll, i generate image with picturebox, for my ASP project.(image for authentication to avoid spam
> robots)
> b) Now i dont want to save this image to disk on server
> c) I want to write picturebox image "directly" to ADO Stream and then Response.BinaryWrite to display image on my ASP
> page.

In that case you probably don't want to use Bitmap as the image format you're working with, you'd likely be better off
using JPEG, GIF of PNG for example. To this end, grab a copy of FreeImage and use it's FreeImage_SaveToMemory() method
to save the image to a buffer in whatever format you choose, which can then go into your ADO stream.
When you use Response.BinaryWrite() to display the image, it looks like you need to set some other properties on it too
(MIME type for example), have a look for "ImageOutput.asp" on this page for an example:
http://www.15seconds.com/issue/990923.htm
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> OLE All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group