【问题标题】:Display horizontal and vertical images in imageview在 imageview 中显示水平和垂直图像
【发布时间】:2015-02-26 18:54:31
【问题描述】:

我正在从我的应用程序的 SD 卡中获取图片。我正在使用 imageview 来显示图像。但是,由于我不知道图像是水平的还是垂直的,如何在 imageview 中适当地显示水平或垂直图像。谢谢

 File img_file = new File(picture_path);
        bm = BitmapFactory.decodeFile(img_file.getAbsolutePath());
        iv2.setImageBitmap(bm);

图像视图 xml

 <ImageView
    android:id="@+id/iv_image2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    />

【问题讨论】:

    标签: android


    【解决方案1】:

    不幸的是,这是一件很复杂的事情。您可以读取 Xif 数据并确定其方向,请参阅 How to determine orientation of picture without ExifInterface?Android get Orientation of a camera Bitmap? And rotate back -90 degrees 获取想法。然后你可以手动旋转它。

    【讨论】:

    • 我在这里试图理解,图像是水平或垂直显示的。它们不需要旋转。我的问题是,如果我在 imageview 中对宽度和高度进行硬编码,纵向图像的高度看起来很奇怪?有点缩水了。有什么想法吗?
    • 啊...不要硬编码宽度和高度。两者都使用 wrap_content。这将使规模正确。如果您想制作硬编码的图像大小,则必须告诉它如何缩放或裁剪,这是您的选项列表:developer.android.com/reference/android/widget/…
    • 感谢您的意见。我真的很感激
    猜你喜欢
    • 2011-03-11
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多