如何在C ++ UWP项目中使用TimeSpan-Elements初始化和填充IVector?

时间:2017-06-20 13:21:12

标签: uwp c++-cx iterable

我正在尝试在C ++ / CX UWP项目中以定义的时间间隔从现有视频中截取屏幕截图。我的想法是使用MediaComposition Library

中的函数“GetThumbnailsAsync”
    create_task(MediaClip::CreateFromFileAsync(this->last_video)).then([this](MediaClip^ clip )
{
    // Create a MediaComposition containing the clip and set it on the MediaElement.
    MediaComposition^ composition = ref new MediaComposition();
    composition->Clips->Append(clip);

    TimeSpan ts;
    ts.Duration = 1000;

    IVector<TimeSpan>^ i_ts_vector;
    //TODO

    create_task(composition->GetThumbnailsAsync(is_ts_vector, 0, 0, VideoFramePrecision::NearestFrame)).then([this, clip, composition](IVectorView<ImageStream^>^ imageStream)
    {
        //TODO
    });
});

last_video是一个带有视频路径的StorageFile。

这不起作用,因为i_ts_vector未初始化且仍为NULL。我已经尝试过这样的事情:

IVector<TimeSpan>^ i_ts_vector = ref new Vector<TimeSpan>();

这适用于int-vectors,但不适用于TimeSpan-vectors。它给出了编译器错误:

  

错误C2678二进制'==':找不到哪个运算符带有'const Windows :: Foundation :: TimeSpan'类型的左手操作数(或者没有可接受的转换)

如何使用TimeSpan-Elements初始化和填充IVector?或者有更好的方法来截取屏幕截图吗?

Corono

1 个答案:

答案 0 :(得分:0)

这里的问题是(参考Value types in Vector

  

要存储在Platform::Collections::Vector中的任何元素必须支持相等比较,无论是隐式还是使用您提供的自定义std::equal_to比较器。所有引用类型和所有标量类型都隐式支持相等比较。对于非标量值类型(例如Windows::Foundation::DateTime)或自定义比较(例如,class Customer(Base): __tablename__ = "customers" id = Column(Integer, primary_key=True) name = Column(String, nullable=False) img = Column(String, nullable=False) auth_token = Column(String, nullable=True) notification_config = Column(JSONB, nullable=True) admin_id = Column(Integer, nullable=True) user_id = Column(MutableDict.as_mutable(HSTORE)) 必须提供自定义函数对象。

Time​Span Struct也是没有相等操作("""Added user_id, admin_id and role to Customer Revision ID: 1ebe3d18442f Revises: 88b4dccb5c1e Create Date: 2017-06-21 17:03:21.181933 """ # revision identifiers, used by Alembic. revision = '1ebe3d18442f' down_revision = '88b4dccb5c1e' branch_labels = None depends_on = None from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('customers', sa.Column('admin_id', sa.Integer(), nullable=True)) op.add_column('customers', sa.Column('auth_token', sa.String(), nullable=True)) op.add_column('customers', sa.Column('user_id', postgresql.HSTORE(text_type=Text()), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('customers', 'user_id') op.drop_column('customers', 'auth_token') op.drop_column('customers', 'admin_id') # ### end Alembic commands ### )的非标量值类型之一。所以你得到了objA->UniqueID == objB->UniqueID—you。要解决此问题,您可以提供如下所示的自定义函数:

operator==

然后在Platform::Collections::Vector中使用它,如:

Error C2678