converting Buffer to Picture 
Author Message
 converting Buffer to Picture

Hi!
Does anyone know how to convert the buffer obtained from IBasicVideo into a
Picture?

TIA,
Pablo

Code:
Dim buffersize, dibimage(),lPtr, pwidth, pheight As Long
Dim gPic As Picture
Dim g_objMC As IMediaControl
Dim g_objBasic As IBasicVideo

Set g_objBasic = g_objMC
g_objBasic.GetVideoSize pwidth, pheight
buffersize = pwidth * pheight
ReDim dibimage(0 To buffersize) As Long
lPtr = VarPtr(dibimage(0))

g_objBasic.GetCurrentImage buffersize, lPtr
' assign that buffer to gPic



Sun, 10 Nov 2002 03:00:00 GMT  
 converting Buffer to Picture

First you need to make an HBitmap from the buffer, and then the HBitmap a
Picture. This is the code I use, not very efficient but works. Watch your
variable declarations, you seem to be declaring variants instead of longs.

Public Function CreateHBitmapFromCurrentFrame(Video As IBasicVideo, hDC As
Long) As Long
    Dim buf() As Long
    Dim l As Long, Width As Long, Height As Long
    Video.GetVideoSize Width, Height
    l = Width * Height * 4
    ReDim buf(0 To l)

    Video.GetCurrentImage l, buf(0)

    Dim h As BITMAPINFOHEADER
    Dim pBmpBits As Long
    Dim hBitmap As Long

    CopyMemory h, buf(0), buf(0)
    pBmpBits = VarPtr(buf(0)) + h.biClrUsed + h.biSize

    hBitmap = MyCreateDIBitmap(hDC, buf(0), CBM_INIT, pBmpBits, buf(0),
DIB_RGB_COLORS)
    SetBitmapDimensionEx hBitmap, h.biWidth, h.biHeight, 0
    CreateHBitmapFromCurrentFrame = hBitmap
End Function

Public Function CreateBitmapPicture(ByVal hBmp As Long, _
   ByVal hPal As Long) As Picture

   Dim r As Long
   Dim Pic As PicBmp
   ' IPicture requires a reference to "Standard OLE Types"
   Dim ipic As IPicture
   Dim IID_IDispatch As GUID

   ' Fill in with IDispatch Interface ID
   With IID_IDispatch
      .Data1 = &H20400
      .Data4(0) = &HC0
      .Data4(7) = &H46
   End With

   ' Fill Pic with necessary parts
   With Pic
      .Size = Len(Pic)          ' Length of structure
      .Type = vbPicTypeBitmap   ' Type of Picture (bitmap)
      .hBmp = hBmp              ' Handle to bitmap
      .hPal = hPal              ' Handle to palette (may be null)
   End With

   ' Create Picture object
   r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, ipic)
    'r = OleCreatePictureIndirect(hBmp, IID_IDispatch, 1, IPic)
   ' Return the new Picture object
   Set CreateBitmapPicture = ipic
End Function


Quote:
> Hi!
> Does anyone know how to convert the buffer obtained from IBasicVideo into
a
> Picture?

> TIA,
> Pablo

> Code:
> Dim buffersize, dibimage(),lPtr, pwidth, pheight As Long
> Dim gPic As Picture
> Dim g_objMC As IMediaControl
> Dim g_objBasic As IBasicVideo

> Set g_objBasic = g_objMC
> g_objBasic.GetVideoSize pwidth, pheight
> buffersize = pwidth * pheight
> ReDim dibimage(0 To buffersize) As Long
> lPtr = VarPtr(dibimage(0))

> g_objBasic.GetCurrentImage buffersize, lPtr
> ' assign that buffer to gPic



Mon, 30 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. convert embedded pictures to linked pictures??

2. How to make buffers to Picture Box?

3. DD7 Double buffering, rotation of picture in surface

4. String Buffer to Picture Object

5. String Buffer to Picture Object

6. Paasing Struct containg Pointers to buffer and len of buffer to Dll

7. Converting picture wrapformat to inline

8. Convert Object to Picture

9. Convert a Picture Object to an InlineShape Object

10. Convert Excel Link into a Picture format?

11. Hjw to convert ActiveX to Picture format from VBA

12. Convert a picture to string and get it back

 

 
Powered by phpBB® Forum Software