Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [vb.net] Problema snapshot con directshow lib
Forum - C# / VB.NET - [vb.net] Problema snapshot con directshow lib

Avatar
evil ways (Normal User)
Rookie


Messaggi: 26
Iscritto: 06/01/2010

Segnala al moderatore
Postato alle 22:27
Giovedì, 05/07/2012
salve a tutti,
ho creato un applicazione che scatta degli snapshot su un file in riproduzione all'interno del programma usando la libreria DirectShow. Ecco il codice:
Codice sorgente - presumibilmente VB.NET

  1. Dim Buff As Long
  2.         Dim zero As IntPtr = IntPtr.Zero
  3.         Dim Mstep As Integer
  4.         Dim bit1 As Bitmap
  5.         basicVideo.GetCurrentImage(Buff, zero)
  6.         zero = Marshal.AllocCoTaskMem(Buff)
  7.         basicVideo.GetCurrentImage(Buff, zero)
  8.         Dim gg As New BitmapInfoHeader
  9.         Marshal.PtrToStructure(zero, gg)
  10.         Mstep = gg.ImageSize / gg.Height
  11.         bit1 = New Bitmap(gg.Width, gg.Height, Mstep, Imaging.PixelFormat.Format32bppRgb, zero)
  12.         bit1.RotateFlip(RotateFlipType.RotateNoneFlipY)
  13.         Dim bm_dest As New Bitmap(gg.Width, gg.Height)
  14.         Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
  15.         gr_dest.DrawImage(bit1, 0, 0, _
  16.                 bm_dest.Width + 1, _
  17.                 bm_dest.Height + 1)
  18.         bm_dest.Save("c:\1.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
  19.         PictureBox1.Image = Nothing
  20.         PictureBox1.Image = bit1
  21.         PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize



Per darvi un'idea ecco l'immagine corrotta:
[URL=http://thumbnails7.imagebam.com/20022/a28bfd200212010.jpg[ ...'>http://www.imagebam.com/image/a28bfd200212010][IMG]http:// ...]

Come potete notare c'è una strisciolina a sinistra che dovrebbe essere a destra...
sapete aiutarmi?


evil ways ha allegato un file: 2012-07-05_221721.jpg (35129 bytes)
Clicca qui per guardare l'immagine

Ultima modifica effettuata da evil ways il 05/07/2012 alle 22:29
PM Quote
Avatar
ampeg (Normal User)
Pro


Messaggi: 124
Iscritto: 21/04/2011

Segnala al moderatore
Postato alle 11:49
Venerdì, 06/07/2012
da una prima occhiata veloce potrebbe essere che l'argomento n.3 (MStep) del costruttore della classe bitmap che genera l'immagine "bit1" ha un valore che sballa l'offset dell'immagine

controlla che soddisfi i requisiti del costruttore

http://msdn.microsoft.com/it-it/library/zy1a2d14.aspx

PM Quote
Avatar
evil ways (Normal User)
Rookie


Messaggi: 26
Iscritto: 06/01/2010

Segnala al moderatore
Postato alle 19:47
Giovedì, 12/07/2012
Grazie ampeg per la dritta ho risolto ecco il codice

Codice sorgente - presumibilmente VB.NET

  1. Dim Buff As Long
  2.         Dim zero As IntPtr = IntPtr.Zero
  3.         Dim Mstep As Integer
  4.         Dim bit1 As Bitmap
  5.         basicVideo.GetCurrentImage(Buff, zero)
  6.         zero = Marshal.AllocCoTaskMem(Buff)
  7.         basicVideo.GetCurrentImage(Buff, zero)
  8.         Dim gg As New BitmapInfoHeader
  9.         Marshal.PtrToStructure(zero, gg)
  10.         Mstep = gg.Width * CInt((gg.BitCount / 8))
  11.         bit1 = New Bitmap(gg.Width, gg.Height, -Mstep, Imaging.PixelFormat.Format32bppRgb, CType((zero.ToInt32() + gg.Size + gg.ImageSize - Mstep), IntPtr))
  12.         Dim bm_dest As New Bitmap(gg.Width, gg.Height)
  13.         Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
  14.         gr_dest.DrawImage(bit1, 0, 0, _
  15.                 bm_dest.Width + 1, _
  16.                 bm_dest.Height + 1)
  17.         bm_dest.Save("c:\0" & ics & ".jpg", System.Drawing.Imaging.ImageFormat.Bmp)
  18.         'Threading.Thread.Sleep(1000)


PM Quote