Results 1 to 12 of 12

Thread: memory and bitmaps for AVI

  1. #1

    Thread Starter
    Lively Member jayantkumble's Avatar
    Join Date
    Feb 2002
    Posts
    65

    Smile memory and bitmaps for AVI

    hi,
    i'm writing an app for running and editing AVI movie files. Using the api AVIStreamGetFrame i get a video frame from the avi file into memory and have a pointer to use it but i want to display this memory block into a picturebox frame by frame. i used CopyMemory to do this still i didn't get any result can any one please help me out with this.
    do i have to create a compatible DC and then blit everthing to the picturebox's DC from the compatible DC, if so then how should i get this memory bitmap on to the compitable DC first?

  2. #2

    Thread Starter
    Lively Member jayantkumble's Avatar
    Join Date
    Feb 2002
    Posts
    65
    hi,
    well i solved some of the part of the problem, i.e. getting the bitmap image from the memory to the DC of the picture box.

    But the image is displayed vertically flipped. How should i get the image to be display properly(say flip it again to make it vertically correct)

    This is the way i got the image from memory to the picturebox,
    1) the AVIGetStreamFrame function returns a pointer to the bitmap image in memory, so i created an object of type BITMAP and got the bitmap image into this object,

    Dim bmp as BITMAP

    bmp.bmBits = AVIGetStreamFrame(pPointerToStream, nFrameNo)

    2) then i created a DC compatible to the picturebox's DC

    dim myDC as long

    myDC = CreateCompatibleDC(picturebox1.hdc)

    3) i got the bitmap on to this DC

    SelectObject(myDC, bmp)

    i couldn't do the same(i.e. selectobject(picturebox.hdc,bmp)) with the picturebox's DC, i don't know why. Any guesses?

    4) then i used the bitblt function to get the bitmap from myDC to the picturebox's DC

    BitBlt(picture1.hdc, destX, destY, width, height, myDC, srcX, srcY, SRCCOPY)

    now i have the bitmap image on my picturebox but it is vertically flipped coz bitmap images are saved vertically flipped in BMP image files and i guess AVI files too.

    plz help me in getting the image displayed correctly.

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Use StretchBlt:
    VB Code:
    1. StretchBlt(picture1.hdc, destX, destY+height, width, -height, myDC, srcX, srcY, width, height, SRCCOPY)
    That should work... I might have some of the syntax wrong but the point is to flip the height, by using Y at the bottom and negative height.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can select bitmaps only into memory DCs.

    StretchBlt is slow. I think it would be more efficient to write a function that flips the bitmap. Except of course that this is VB...
    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.

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Except of course that this is VB...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    StretchBlt isn't that slow; its certainly fast enough to use it for inverting a single frame. Playing back the AVI you would NOT want to do with StretchBlt every frame, though
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Just what I mean.
    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.

  8. #8

    Thread Starter
    Lively Member jayantkumble's Avatar
    Join Date
    Feb 2002
    Posts
    65
    i did use stretchblt for playing the AVI movie frame by frame, well i didn't find any prob with the speed(maybe coz they where small files), but if there is any other better way to do this other than using the MCI control then plz let me know.
    theres a new problem now.
    The image being displayed shifts a bit to the right having some part of the images right side to be displayed on the left.
    And the other problem is with the color, BMP files have each pixel represented as BGR in the file (i guess the same happens with AVI also), thats why i'm not getting the colors right when the bitmap is displayed in the picturebox. How can i change the bits from BGR to RGB or vice-vresa.

    well i have made a mistake in representing the steps in which
    i got the bitmap from memory to the picturebox,
    thats the step 3
    selectobject(someDC, bmp)

    actually theres a step before this i.e. to get a handle to the bitmap using some function called CreateBitmap or something
    hBMP = CreateBitmap..(bmp)

    then i selected the bitmap
    selectobject(someDC, hBMP)
    Last edited by jayantkumble; Oct 14th, 2002 at 11:44 AM.

  9. #9
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Not tested, but this should work for converting a BGR to RGB:


    VB Code:
    1. Public Function BGRtoRGB(Byval BGR as Long) As Long
    2.  Dim R As Byte, G As Byte, B As Byte
    3.  
    4.  R = BGR And &HFF
    5.  G = BGR And &HFF00
    6.  B = BGR And &HFF0000
    7.  
    8.  BGRtoRGB = RGB(R,G,B)
    9. End Function
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Correct me if wrong, but the last line should read RGB(B, G, R), should it not? Because you are getting the red from BGR where the blue should be, etc, and by not inverting it, you will end up with the same colour.

    Yes, I just tested it, and you need to switch it:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim A As Long
    3.  
    4.     A = RGB(255, 0, 0) 'BGR notation though, so it's actually RGB(0,0,255)
    5.     MsgBox A
    6.     A = BGRtoRGB(A)
    7.     MsgBox A
    8.    
    9. End Sub
    10. Private Function BGRtoRGB(ByVal BGR As Long) As Long
    11.  Dim R As Byte, G As Byte, B As Byte
    12.  
    13.  R = BGR And &HFF
    14.  G = BGR And &HFF00
    15.  B = BGR And &HFF0000
    16.  
    17.  BGRtoRGB = RGB(B, G, R)
    18. End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    lol that's correct... my mistake, I got confused there
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  12. #12

    Thread Starter
    Lively Member jayantkumble's Avatar
    Join Date
    Feb 2002
    Posts
    65
    thnx guys!

    The bitmaps bits are in a BITMAP structure say, mybmp. access by the member bmBits that would be mybmp.bmBits
    here the first byte is the color Blue the second Green and the third Red and i guess the fourth one is for alpha so do you think the following will work?

    For i = 0 To (mybmp.bmWidth * mybmp.bmHeight)*4
    a = rgb(mybmp.bmBits + i, mybmp.bmBits + i +1 , mybmp.bmBits + i + 2)
    a = BGRtoRGB(a)
    Next

    is there anything better than StretchBlt??
    has anyone tried the code from my second reply to the post. if yes did anyone have porb with the way the picture is displayed(not the colors)

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