Article View: microsoft.public.vb.winapi.graphics
Article #5stream to bmp in API
From: S�bastien Dionne
Date: Fri, 11 Sep 1998 00:00
Date: Fri, 11 Sep 1998 00:00
114 lines
4802 bytes
4802 bytes
I have this code... I wanna save each frame in a bmp file.. how I can do
that ?
#include <windows.h>
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <commdlg.h>
#include <vfw.h>
#include <memory.h>
DWORD dwImageSize = (DWORD)320 * (DWORD)240 * 3; // 640 * 480 *
24 bpp
void AviPlayer(HWND hWnd, char* szFilename)
{
PAVIFILE pavif;
PAVISTREAM pavis;
AVIFILEINFO afi;
LPBITMAPINFOHEADER biFmt;
LPSTR szBuffering;
HDC hdcDisplay;
HDRAWDIB hddOp;
LONG lIndex, lLength;
// Initialisation du sous-syst�me AVI
AVIFileInit();
// Ouverture du fichier utilisateur en mode lecture seule et en
mode partage
AVIFileOpen(&pavif, szFilename, OF_READ, NULL);
// R�cup�ration des informations sur le copyright, stream name,
etc.
AVIFileInfo(pavif, &afi, sizeof(AVIFILEINFO));
// Trouver le premier flux video (obligatoire)
AVIFileGetStream(pavif, &pavis, streamtypeVIDEO, 0);
// Taille en octets d'un bloc video
AVIStreamFormatSize(pavis, 0, &lLength);
// Allocation de de l'espace n�cessaire en fonction du format
biFmt =
(LPBITMAPINFOHEADER)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
lLength);
szBuffering = (LPSTR)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, dwImageSize);
// Obtention du DC pour l'affichage
hdcDisplay = GetWindowDC(hWnd);
// Lecture du format d'un bloc sur la sortie video
AVIStreamReadFormat(pavis, 0, biFmt, &lLength);
// Combien de frames contient le flux video ?
lLength = AVIStreamLength(pavis);
// Retailler le fen�tre a la taille exacte du film
SetWindowPos(hWnd, HWND_TOP, 0, 0, (UINT)biFmt->biWidth,
(UINT)biFmt->biHeight, SWP_NOMOVE);
// Cr�ation de l'objet DrawDib
hddOp = DrawDibOpen();
// Initialisation des propri�t�s de l'objet DrawDib
DrawDibBegin(hddOp, hdcDisplay, 0, 0, biFmt,
(UINT)biFmt->biWidth,(UINT)biFmt->biHeight,
DDF_SAME_HDC);
// Finalement afficher la fen�tre
ShowWindow(hWnd, SW_RESTORE);
// Maintenant faire une boucle sur la lecture du flux videopour
lire l'ensemble des
// frame le plus rapidement possible. Les frames video sont
d�compress�es par la
// fonction AVIStreamRead() en DIBs (dans le buffer
szBuffering) ainsi nous n'avons
// pas � nous pr\eoccuper de la d�compression.
for (lIndex = 0; lIndex < lLength; ++lIndex) {
LONG uLong = dwImageSize;
AVIStreamRead(pavis, lIndex, 1, szBuffering, dwImageSize,
&uLong, NULL);
DrawDibDraw(hddOp, hdcDisplay, 0, 0, (UINT)biFmt->biWidth,
(UINT)biFmt->biHeight, biFmt, szBuffering, 0,
0,
(UINT)biFmt->biWidth, (UINT)biFmt->biHeight,
0);
} // Affichage de chaque Frame
// R�afficher la fen�tre application
ShowWindow(hWnd, SW_HIDE);
ShowWindow(hWnd, SW_SHOW);
// Lib�ration du DC
ReleaseDC(hWnd, hdcDisplay);
// Lib�ration des ressources du flux video
AVIStreamRelease(pavis);
AVIFileRelease(pavif);
// Lib�ration de la m�moire allou�e
HeapFree(GetProcessHeap(), 0, (LPVOID)biFmt);
HeapFree(GetProcessHeap(), 0, (LPVOID)szBuffering);
// Fermeture de l'objet DrawDib et du sous-syst�me AVI
DrawDibClose(hddOp);
AVIFileExit();
}
Technical Details
Message-ID:
<35F9852D.F275496A@gel.usherb.ca>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: FRENCH,ASCII X-Google-Thread: 1138df,61d494177feebd46,start X-Google-Attributes: gid1138df,public X-Google-Thread: 10e433,61d494177feebd46,start X-Google-Attributes: gid10e433,public X-Google-Thread: 102f44,61d494177feebd46,start X-Google-Attributes: gid102f44,public X-Google-Thread: 104d65,61d494177feebd46,start X-Google-Attributes: gid104d65,public X-Google-Thread: 104093,61d494177feebd46,start X-Google-Attributes: gid104093,public X-Google-Thread: f5ca7,61d494177feebd46,start X-Google-Attributes: gidf5ca7,public From: "S�bastien Dionne" <dios01@gel.usherb.ca> Subject: stream to bmp in API Date: 1998/09/11 Message-ID: <35F9852D.F275496A@gel.usherb.ca> X-Deja-AN: 390219919 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=iso-8859-1 MIME-Version: 1.0 NNTP-Posting-Date: Fri, 11 Sep 1998 16:16:19 EDT Newsgroups: microsoft.public.vb.winapi.graphics,microsoft.public.vb.winapi,comp.os.ms-windows.programmer.tools.mfc,borland.public.cppbuilder.winapi,borland.public.cppbuilder.graphics,microsoft.public.vc.mfc