如何从xamarin格式的视频生成缩略图
我们正在使用Xamarin表单录制视频应用程序如何从xamarin格式的视频生成缩略图,xamarin,xamarin.forms,video-thumbnails,Xamarin,Xamarin.forms,Video Thumbnails,我们正在使用Xamarin表单录制视频应用程序 我的问题是如何从Xamarin格式的视频中生成缩略图?在iOS上,您可以这样做: public ImageSource GenerateThumbImage(string url, long usecond) { AVAssetImageGenerator imageGenerator = new AVAssetImageGenerator(AVAsset.FromUrl((new Foundation.NSUrl(url)))
我的问题是如何从Xamarin格式的视频中生成缩略图?在iOS上,您可以这样做:
public ImageSource GenerateThumbImage(string url, long usecond)
{
AVAssetImageGenerator imageGenerator = new AVAssetImageGenerator(AVAsset.FromUrl((new Foundation.NSUrl(url))));
imageGenerator.AppliesPreferredTrackTransform = true;
CMTime actualTime;
NSError error;
CGImage cgImage = imageGenerator.CopyCGImageAtTime(new CMTime(usecond, 1000000), out actualTime, out error);
return ImageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream());mageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream());
}
在Android上:
public ImageSource GenerateThumbImage(string url, long usecond)
{
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.SetDataSource(url, new Dictionary<string, string>());
Bitmap bitmap = retriever.GetFrameAtTime(usecond);
if (bitmap != null)
{
MemoryStream stream = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
byte[] bitmapData = stream.ToArray();
return ImageSource.FromStream(() => new MemoryStream(bitmapData));
}
return null;
}
public-ImageSource-GenerateThumbImage(字符串url,long-usecond)
{
MediaMetadataRetriever retriever=新的MediaMetadataRetriever();
SetDataSource(url,new Dictionary());
位图位图=retriever.GetFrameAtTime(usecond);
if(位图!=null)
{
MemoryStream stream=新的MemoryStream();
Compress(bitmap.CompressFormat.Png,0,流);
字节[]位图数据=stream.ToArray();
返回ImageSource.FromStream(()=>newmemoryStream(bitmapData));
}
返回null;
}
您可以告诉我们您计划支持哪些平台,因为任何视频录制/操作都非常依赖于平台。我们需要同时使用ios和android平台。ios代码不起作用。我将CGIV象对象返回到iOS上的(null),尝试使用-NSUrl.FromFilename(PATH)代替-NealFund。NSUrl(URL)