PC Review


Reply
Thread Tools Rate Thread

bitmap from video file source available?

 
 
William Johnston
Guest
Posts: n/a
 
      3rd Jul 2008

Hi,

I get an infinite loop and non-"optimal" results from an MSDN Magazine March 2007 article on creating bitmaps from video files.

The infinite loop and non-"optimal" results are from a Microsoft Support Technician.

Does anyone have better code or better workarounds?

Here is my code:

private void CreateThumbnail(string file, string outputDir)
{
try
{
MediaPlayer mp = new MediaPlayer();
mp.Open(new Uri(file));
mp.Position = new TimeSpan(00, 00, 00);
Workaround(mp);

RenderTargetBitmap rtb = new RenderTargetBitmap(260, 184, 1 / 200, 1 / 200, PixelFormats.Pbgra32);

DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
RectAnimation ra = new RectAnimation();
dc.DrawVideo(mp, new Rect(0, 0, 260, 184));

dc.Close();
rtb.Render(dv);

string filename = GetFileName(file);

//create the output filename
object[] formatParams = new object[2];
formatParams[0] = outputDir;
formatParams[1] = filename;

string outputFileName = null;

outputFileName = string.Format("{0}\\{1}_thumbnail.bmp", formatParams);

BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));

using (FileStream writer = new FileStream(outputFileName, FileMode.Create))
{
System.Console.WriteLine("Saving [{0}]", outputFileName);
encoder.Save(writer);
}
mp.Close();
mp = null;
}
catch (Exception e)
{
System.Console.WriteLine("CreateThumbnail: " + e.Message);
System.Environment.Exit(1);
}
}

private void Workaround(MediaPlayer mp)
{
mp.Play();
TimeSpan startPosition = mp.Position;
while (startPosition == mp.Position)
{
System.Threading.Thread.Sleep(1000);
}
mp.Pause();
}


Regards,
williamj


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting picture files to Excel - always bitmap even if source jpeg =?Utf-8?B?TWF0dCBMYXdzb24=?= Microsoft Excel Misc 2 23rd Nov 2004 03:04 PM
How to copy a part of a source bitmap? ΢ÈíÐÂÎÅ×é Microsoft C# .NET 1 22nd Mar 2004 10:07 AM
Video Thumb - view video source Susan Bugher Freeware 3 16th Mar 2004 06:05 PM
Question on how to access bitmap: Public Function getBitmap() As Bitmap Michael Murphy Microsoft VB .NET 2 7th Oct 2003 01:54 PM
extract OLE bitmap from table and save as a bitmap file Brett Rawcliffe Microsoft Access 1 19th Jul 2003 03:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 AM.