|
-
Oct 11th, 2002, 11:10 AM
#1
Thread Starter
Lively Member
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?
-
Oct 12th, 2002, 11:04 AM
#2
Thread Starter
Lively Member
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.
-
Oct 12th, 2002, 11:08 AM
#3
Good Ol' Platypus
Use StretchBlt:
VB Code:
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)
-
Oct 13th, 2002, 12:39 PM
#4
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.
-
Oct 13th, 2002, 01:23 PM
#5
Good Ol' Platypus
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)
-
Oct 13th, 2002, 08:08 PM
#6
Frenzied Member
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
-
Oct 14th, 2002, 04:29 AM
#7
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.
-
Oct 14th, 2002, 11:35 AM
#8
Thread Starter
Lively Member
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.
-
Oct 14th, 2002, 12:20 PM
#9
Frenzied Member
Not tested, but this should work for converting a BGR to RGB:
VB Code:
Public Function BGRtoRGB(Byval BGR as Long) As Long
Dim R As Byte, G As Byte, B As Byte
R = BGR And &HFF
G = BGR And &HFF00
B = BGR And &HFF0000
BGRtoRGB = RGB(R,G,B)
End Function
-
Oct 14th, 2002, 12:29 PM
#10
Good Ol' Platypus
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:
Private Sub Form_Load()
Dim A As Long
A = RGB(255, 0, 0) 'BGR notation though, so it's actually RGB(0,0,255)
MsgBox A
A = BGRtoRGB(A)
MsgBox A
End Sub
Private Function BGRtoRGB(ByVal BGR As Long) As Long
Dim R As Byte, G As Byte, B As Byte
R = BGR And &HFF
G = BGR And &HFF00
B = BGR And &HFF0000
BGRtoRGB = RGB(B, G, R)
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)
-
Oct 14th, 2002, 01:48 PM
#11
Frenzied Member
lol that's correct... my mistake, I got confused there
-
Oct 16th, 2002, 09:36 AM
#12
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|