如何在C+中初始化IVector并用TimeSpan元素填充它+;UWP项目?

如何在C+中初始化IVector并用TimeSpan元素填充它+;UWP项目?,uwp,c++-cx,iterable,Uwp,C++ Cx,Iterable,我试图在一个C++/CX UWP项目中,在一个定义的时间间隔内从现有视频中截取屏幕截图。我的想法是使用函数“GetThumbnailsAsync”,该函数来自: create_任务(MediaClip::CreateFromFileAsync(this->last_video))。然后([this](MediaClip^clip) { //创建包含剪辑的MediaComposition并将其设置在MediaElement上。 MediaComposition^composition=ref新Me

我试图在一个C++/CX UWP项目中,在一个定义的时间间隔内从现有视频中截取屏幕截图。我的想法是使用函数“GetThumbnailsAsync”,该函数来自:

create_任务(MediaClip::CreateFromFileAsync(this->last_video))。然后([this](MediaClip^clip)
{
//创建包含剪辑的MediaComposition并将其设置在MediaElement上。
MediaComposition^composition=ref新MediaComposition();
合成->剪辑->附加(剪辑);
时间跨度ts;
ts.持续时间=1000;
IVector^i\u ts\u向量;
//待办事项
创建任务(合成->GetThumbnailsAsync(是向量,0,0,VideoFramePrecision::NearestFrame))。然后([这个,剪辑,合成](IVectorView^imageStream)
{
//待办事项
});
});
最后一个视频是带有视频路径的存储文件

这不起作用,因为i\u ts\u向量未初始化且仍然为空。我已经试过这样的方法:

IVector<TimeSpan>^ i_ts_vector = ref new Vector<TimeSpan>();
IVector^i\u ts\u vector=ref new vector();
这适用于int向量,但不适用于TimeSpan向量。它给出了一个编译器错误:

错误C2678二进制“==”:未找到接受类型为“const Windows::Foundation::TimeSpan”的左侧操作数的运算符(或没有可接受的转换)

如何用TimeSpan元素初始化和填充IVector?还是有更好的截图方法

科罗诺

这里的问题是(参考)

要存储在中的任何元素都必须支持相等比较,可以隐式地,也可以使用您提供的自定义比较器。所有引用类型和所有标量类型都隐式支持相等比较。对于非标量值类型,例如,或对于自定义比较,例如,
objA->UniqueID==objB->UniqueID,您必须提供自定义函数对象

也是不具有相等操作的非标量值类型之一(
运算符==
)。所以您得到了
错误C2678
。要解决此问题,可以提供如下自定义函子:

struct MyEqual : public std::binary_function<const TimeSpan, const TimeSpan, bool>
{
    bool operator()(const TimeSpan& _Left, const TimeSpan& _Right) const
    {
        return _Left.Duration == _Right.Duration;
    }
};
struct MyEqual:public std::binary_函数
{
布尔运算符()(常量时间跨度和左,常量时间跨度和右)常量
{
返回_Left.Duration==_Right.Duration;
}
};
然后将其用于类似:

IVector^i_ts_vector=ref新平台::集合::向量();

非常确定您可以使用
auto i_ts_vector=ref new vector()
auto i_ts_vector=ref new vector()给出了相同的错误:错误C2678二进制“==”:未找到接受类型为“const Windows::Foundation::TimeSpan”的左侧操作数的运算符(或没有可接受的转换)
struct MyEqual : public std::binary_function<const TimeSpan, const TimeSpan, bool>
{
    bool operator()(const TimeSpan& _Left, const TimeSpan& _Right) const
    {
        return _Left.Duration == _Right.Duration;
    }
};
IVector<TimeSpan>^ i_ts_vector = ref new Platform::Collections::Vector<TimeSpan, MyEqual>();