【问题标题】:Bitmap not scaling to imageView位图不缩放到 imageView
【发布时间】:2016-09-30 17:31:53
【问题描述】:

我不完全明白我的问题出在哪里,所以我会提供尽可能多的信息,其中一些可能与找到答案无关,但其中一些可能会有所帮助。

问题

我已将相机集成到我的应用程序中,我正在使用 surfaceView 来显示相机的预览,在捕获图像时我获取原始图像字节和通过 ObjectOutput 流发送它们,我将在该流中显示该活动的图像。这是该代码的 sn-p:

out = new ObjectOutputStream(new FileOutputStream(new File(getActivity().getCacheDir(),"")+"cacheFile.srl"));
out.writeObject(bytes);

在另一个活动中,我读取字节并显示图像:

bytes = (byte[]) in.readObject();
image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
myHolder.setImageBitmap(image);

这是显示图像的活动的 XML 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.Home">

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:id="@+id/ih"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"/>

Here is the problem, I need to scale the image to fit the whole activity, yet there is white lines on either side

如果需要任何其他信息,请告诉我并更新帖子

更新 1

我将布局更改为:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    android:id="@+id/ih"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="100dp"/>

但我的两边还是有白线

【问题讨论】:

  • 了解ImageViewscaleTypes
  • 请问您能分享一下图片和您的设备的分辨率吗?

标签: java android xml android-layout bitmap


【解决方案1】:

如果您希望图像适合其边界并剪切其余部分,请将android:scaleType="centerCrop" 设置为ImageView 的属性

您可以在此处找到有关 scaletypes 的更多信息:https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

【讨论】:

  • 我更新了我的帖子,我试过你说的不行,看看原帖的更新
  • 尝试设置 android:adjustViewBounds="true" 也许这会有所帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-02
  • 1970-01-01
  • 2015-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多