如何让缩略图适合图像视图?

发布于 2024-12-11 16:26:08 字数 1048 浏览 1 评论 0原文

我正在从刚刚录制的视频中获取缩略图,并且我需要使缩略图适合图像视图。我用它来调用缩略图:

Bitmap curThumb = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);

我用它来调用图像视图:

image.setImageBitmap(curThumb);

我的图像视图的 xml 看起来像这样:

<ImageView android:id="@+id/iView" android:paddingRight="10px" android:layout_height="280dp" android:layout_width="320dp" android:layout_gravity="center_horizontal" android:paddingTop="5dp" android:paddingBottom="5dp" android:background="@drawable/border"></ImageView>

我用于图像视图背景的边框是一个 xml,它给视图带来了很好的效果白色边框,这是它的以下 xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" shape="oval">

    <stroke android:width="3dp" android:color="#ffffff" />
    <padding android:left="0px" android:top="1dp" android:right="0px"
        android:bottom="1dp" />
    </shape>

我不知道是否是因为我使用的是 MINI_KIND 缩略图,但我需要将其缩小一点,以便它可以完美地适合图像视图。任何帮助就足够了。提前致谢。

I am getting thumbnails from a video that i just recorded and I need to get the thumbnail to fit into an imageview. I am using this to call the thumbnail :

Bitmap curThumb = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);

And I am using this to call the imageview:

image.setImageBitmap(curThumb);

My xml for my imageview looks as such:

<ImageView android:id="@+id/iView" android:paddingRight="10px" android:layout_height="280dp" android:layout_width="320dp" android:layout_gravity="center_horizontal" android:paddingTop="5dp" android:paddingBottom="5dp" android:background="@drawable/border"></ImageView>

The Border that I am using for my background of the image view is an xml which gives the view a nice white border frame, this is follwing xml for it:

<shape xmlns:android="http://schemas.android.com/apk/res/android" shape="oval">

    <stroke android:width="3dp" android:color="#ffffff" />
    <padding android:left="0px" android:top="1dp" android:right="0px"
        android:bottom="1dp" />
    </shape>

I don't know if its because I am using a MINI_KIND thumbnail but i need to cut it down by a little so it can fit into the imageview perfectly. Any help will suffice. Thanks in advance.

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

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

发布评论

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

评论(2

淡墨 2024-12-18 16:26:08

尝试将 android:scaleType="fitCenter" 添加到 ImageView 的属性中。

这将使图像居中并确保(假设它大于 ImageView 的区域)图像覆盖整个区域,并且图像沿至少一个轴完全可见。

Try adding android:scaleType="fitCenter" to the ImageView's attributes.

This will center the image and ensure that (assuming it's larger than the ImageView's area) the image covers the entire area and that the image is completely visible along at least one axis.

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