VideoView 裁剪为正方形

发布于 2024-10-06 21:29:02 字数 405 浏览 0 评论 0原文

使用 ImageView,我可以设置正方形的高度和宽度(例如 100dip x 100dip)。然后使用 android:scaleType="centerCrop" 给我一个被裁剪为正方形的图像,无论宽高比如何。

我们可以使用 VideoView 来做到这一点吗?

我尝试过仅设置正方形的高度和宽度,但它只是重新调整大小以尽可能地填充正方形,同时保持纵横比,我想这完全是预期的。

与 ImageView 不同,它似乎没有任何缩放或裁剪属性/方法,但是 VideoView 文档中的这一点让我觉得我错过了一些东西:

[VideoView] ...提供各种显示选项 例如缩放和着色。

任何想法将不胜感激。

Using an ImageView, I can set a square height and width (say 100dip x 100dip). Then using android:scaleType="centerCrop" gives me an image which is cropped to square regardless of aspect ratio.

Can we do this with a VideoView?

I've tried just setting a square height and width, but it just re-sizes to fill the square as best as it can while maintaining the aspect ratio, which I guess is completely expected.

It doesn't seem to have any scale or crop properties / methods unlike ImageView, but this in the VideoView documentation makes me think I'm missing something:

[VideoView] ...provides various display options
such as scaling and tinting.

Any ideas would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请持续率性 2024-10-13 21:29:02

您可以使用 TextureView 实现视频裁剪效果需要 Android API 14 和硬件加速。我在我的文章此处。

您还可以使用我的 TextureVideoView - 基于 android 的自定义视图TextureView 让您能够轻松播放和裁剪视频。 非常相似

这与 ImageView#setScaleType布局

<com.dd.crop.TextureVideoView
        android:id="@+id/cropTextureView"
        android:layout_width="fill_parent"
        android:layout_height="100dp"/>

代码

TextureVideoView cropTextureView = (TextureVideoView) findViewById(R.id.cropTextureView);
// Use `setScaleType` method to crop video
cropTextureView.setScaleType(TextureVideoView.ScaleType.TOP);
// Use `setDataSource` method to set data source, this could be url, assets folder or path
cropTextureView.setDataSource("http://www.w3schools.com/html/mov_bbb.mp4");
cropTextureView.play();

希望这会对某人有所帮助!

You achive video crop effect using TextureView which require Android API 14 and hardware acceleration. I described it in my article here.

You can also use my TextureVideoView - custom view based on android TextureView which gives you ability to easy play and crop video. This very similar to ImageView#setScaleType

Layout

<com.dd.crop.TextureVideoView
        android:id="@+id/cropTextureView"
        android:layout_width="fill_parent"
        android:layout_height="100dp"/>

Code

TextureVideoView cropTextureView = (TextureVideoView) findViewById(R.id.cropTextureView);
// Use `setScaleType` method to crop video
cropTextureView.setScaleType(TextureVideoView.ScaleType.TOP);
// Use `setDataSource` method to set data source, this could be url, assets folder or path
cropTextureView.setDataSource("http://www.w3schools.com/html/mov_bbb.mp4");
cropTextureView.play();

Hope this will help someone!

月亮邮递员 2024-10-13 21:29:02

来源意味着它不是VideoView 视图本身不支持。您可以复制源代码并使其正常工作。 :) 最有可能的方法是在第 255 行添加 else,修改 onMeasure 以防止其扩展以满足尺寸等。

编辑:
如果参考文档略有偏差或完全错误,请不要感到惊讶。

Source implies that it isn't natively supported in the VideoView view. You could copy the source and make it work though. :) Most likely by adding an else at line 255, modifying onMeasure to prevent it from expanding to meet the size, etc.

Edit:
Don't be surprised that the Reference documentation is slightly off or just plain wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文