Comment afficher une image bmp dans un picture depuis un buffer image

firens Messages postés 68 Date d'inscription lundi 6 novembre 2000 Statut Membre Dernière intervention 24 août 2008 - 7 mars 2006 à 14:40
codesource123 Messages postés 2 Date d'inscription mercredi 7 avril 2010 Statut Membre Dernière intervention 9 août 2011 - 9 août 2011 à 18:12
Bonjour,

j'utilise un framegrabber pour récupérer une image.
Je désirerais pouvoir utiliser mon buffer image pour l'afficher dans un picture de type Bitmap déclaré en CStatic avec MFC

Mon image est bien stockée dans mon pointeur imgBuffer... mais ensuite je ne sais pas comment l'afficher...

Merci d'avance

3 réponses

firens Messages postés 68 Date d'inscription lundi 6 novembre 2000 Statut Membre Dernière intervention 24 août 2008
8 mars 2006 à 09:56
personne n'as une réponse ??
0
SebLinck Messages postés 212 Date d'inscription mardi 17 mai 2005 Statut Membre Dernière intervention 23 juin 2011
21 août 2008 à 14:32
Salut,

Regarde du côté de StretchBit ou Bitblt
C'est un peu tard pour la réponse mais ça pourra toujours servir...
Cordialement,
Sébastien.
0
codesource123 Messages postés 2 Date d'inscription mercredi 7 avril 2010 Statut Membre Dernière intervention 9 août 2011
9 août 2011 à 18:12
public static Bitmap GetFrameFromVideo(string videoFile, double percentagePosition, out double streamLength, Size target)
{
if (videoFile == null)
throw new ArgumentNullException("videoFile");
if (percentagePosition > 1 || percentagePosition < 0)
throw new ArgumentOutOfRangeException("percentagePosition", percentagePosition, "Valid range is 0.0 .. 1.0");
if (target.Width % 4 != 0 || target.Height % 4 != 0)
throw new ArgumentException("Target size must be a multiple of 4", "target");

IMediaDet mediaDet = null;
try
{
_AMMediaType mediaType;
if (openVideoStream(videoFile, out mediaDet, out mediaType))
{
streamLength = mediaDet.StreamLength;

//calculates the REAL target size of our frame
if (target == Size.Empty)
target = getVideoSize(mediaType);
else
{
target = scaleToFit(target, getVideoSize(mediaType));
//ensures that the size is a multiple of 4 (required by the Bitmap constructor)
//************************************************************************************************************************
target.Width -= target.Width% 4;
target.Height -= target.Height % 4;
}

unsafe
{
Size s = getVideoSize(mediaType);
int bmpinfoheaderSize =40; //equals to sizeof(CommonClasses.BITMAPINFOHEADER);

//get size for buffer
int bufferSize = (((s.Width * s.Height) * 24) / 8)+ bmpinfoheaderSize; //equals to mediaDet.GetBitmapBits(0d, ref bufferSize, ref *buffer, target.Width, target.Height);

//allocates enough memory to store the frame
IntPtr frameBuffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(bufferSize);
byte* frameBuffer2 = (byte*)frameBuffer.ToPointer();

//gets bitmap, save in frameBuffer2
mediaDet.GetBitmapBits(streamLength * percentagePosition, ref bufferSize, ref *frameBuffer2, target.Width, target.Height);

//now in buffer2 we have a BITMAPINFOHEADER structure followed by the DIB bits

Bitmap bmp = new Bitmap(target.Width, target.Height, target.Width *3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, new IntPtr(frameBuffer2 + bmpinfoheaderSize));

bmp.RotateFlip(RotateFlipType.Rotate180FlipX);

System.Runtime.InteropServices.Marshal.FreeHGlobal(frameBuffer);
//*************************************************************************************************************************************
//************************************************************************************************************************************

//bmp.SetResolution(600, 600);

return bmp ;
}
}
}
catch (COMException ex)
{
throw new InvalidVideoFileException(getErrorMsg((uint)ex.ErrorCode), ex);
}
finally
{
if (mediaDet != null)
Marshal.ReleaseComObject(mediaDet);
}

throw new InvalidVideoFileException("No video stream was found");
}
0
Rejoignez-nous