【问题标题】:Really need help figuring out why a bitmap is placed on an an image_view incorrectly确实需要帮助弄清楚为什么位图被错误地放置在 image_view 上
【发布时间】:2011-05-14 17:32:45
【问题描述】:

这个问题已经困扰我好几天了,我不知道为什么会这样。我有一个检测人脸的方法,如果检测到人脸,该方法将在画布上沿人脸绘制一个矩形。

这部分工作正常。

问题是,当它显示在我的 xml 文件中的 image_view 上时,它会显示在图像视图的最左侧中间,在一个框中,而不是在宽度为 fill_parent 的中心。

我想到了一个可能的解决方法:将位图设置为 bitmapdrawable,但画布只绘制位图,所以我可以在中间获得 bitmapdrawable,但周围没有红框。

我注释掉了我对可绘制位图的测试,并将其保留为我现在所拥有的......它只显示在 image_view 最左侧的我的 xml 中。请帮忙看看!

我发布到 pastebin 是因为代码有点长(我也在视图翻转器中使用线性布局)。

方法:

http://pastebin.com/KQ5Pmx45

xml:

http://pastebin.com/jbt3j40h

由于我能够检测到人脸,并且我可以将可绘制的位图粘贴到图像按钮并且它居中很好,如果我的问题无法解决,有没有办法让位图绘制周围的矩形?

谢谢!

编辑:我尝试将它实现为 RelativeLayout 并且仍然在做同样的事情:

http://pastebin.com/daqMdXjB

Could this code be getting my way of centering?

    public void processCameraImage(Intent intent) {
        mFlipper.setDisplayedChild(1); // 1 == your second layout
        mThePicture = (ImageView) findViewById(R.id.image_view); //
        cameraBitmap = (Bitmap) intent.getExtras().get("data");

        mThePicture.setImageBitmap(cameraBitmap);
        detectFaces();

    }

【问题讨论】:

  • 我不明白您当前的布局描述。您能否发布您拥有的屏幕截图和您想要的修改后的屏幕截图?

标签: android xml bitmap formatting android-canvas


【解决方案1】:

在 Imageview 标签上使用 android:scaleType="fitCenter" 或 android:scaleType="centerInside" 或 android:scaleType="center" sclaetype attr doc

希望,我正确理解了您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    相关资源
    最近更新 更多