W
William Johnston
Hi,
I modified a thumbnail creation app and get black images since the first second is black as well.
My questions are:
1. How do I set the MediaPlayer.Clock property to start screen capture at two seconds?
2. How do I open a file without using a URI?
Here's the sample code:
private void CreateThumbnail(string file, string outputDir)
{
try
{
Uri uri = new Uri(file);
MediaPlayer mp = new MediaPlayer();
mp.Open(uri);
//mp.Position = new TimeSpan(00, 00, 02);
mp.Clock = new MediaTimeline(new TimeSpan(00, 00, 02)).CreateClock();
RenderTargetBitmap rtb = new RenderTargetBitmap(320, 240, 1 / 200, 1 / 200, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
// RectAnimation ra = new RectAnimation();
// ra.BeginTime = new TimeSpan(00, 00, 02);
// dc.DrawVideo(mp, new Rect(0, 0, 320, 240), ra.CreateClock());
dc.DrawVideo(mp, new Rect(0, 0, 320, 240));
dc.Close();
rtb.Render(dv);
//Image im = new Image();
//im.Source = BitmapFrame.Create(rtb);
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}\\tn_{1}.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);
}
}
catch (Exception e)
{
System.Console.WriteLine("CreateThumbnail: " + e.Message);
System.Environment.Exit(1);
}
}
Any suggestions?
Thanks,
William Johnston
I modified a thumbnail creation app and get black images since the first second is black as well.
My questions are:
1. How do I set the MediaPlayer.Clock property to start screen capture at two seconds?
2. How do I open a file without using a URI?
Here's the sample code:
private void CreateThumbnail(string file, string outputDir)
{
try
{
Uri uri = new Uri(file);
MediaPlayer mp = new MediaPlayer();
mp.Open(uri);
//mp.Position = new TimeSpan(00, 00, 02);
mp.Clock = new MediaTimeline(new TimeSpan(00, 00, 02)).CreateClock();
RenderTargetBitmap rtb = new RenderTargetBitmap(320, 240, 1 / 200, 1 / 200, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
// RectAnimation ra = new RectAnimation();
// ra.BeginTime = new TimeSpan(00, 00, 02);
// dc.DrawVideo(mp, new Rect(0, 0, 320, 240), ra.CreateClock());
dc.DrawVideo(mp, new Rect(0, 0, 320, 240));
dc.Close();
rtb.Render(dv);
//Image im = new Image();
//im.Source = BitmapFrame.Create(rtb);
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}\\tn_{1}.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);
}
}
catch (Exception e)
{
System.Console.WriteLine("CreateThumbnail: " + e.Message);
System.Environment.Exit(1);
}
}
Any suggestions?
Thanks,
William Johnston