保留Aspect,但使用裁剪中心

时间:2017-05-16 08:33:36

标签: image unity3d rawimage

我有GameObjectRawImage组件,使用Texture显示图片。

图像被挤压到对象的大小并改变它的原始比例。

如何将纹理中的图像告诉CropCenter? (例如在Android中)

enter image description here

1 个答案:

答案 0 :(得分:3)

Here is how I do with landscape images :

  1. Create a parent RawImage element called "Mask" (works with UI > Image component too)
  2. Add the UI > Mask component to it
  3. Put your Smurf image (with the `RawImage component) as a child of the "Mask" object
  4. Set the values of the child'RectTransform :
    • Anchors Min = (0.5, 0),
    • Anchors Max = (0.5, 1)
    • Top = 0
    • Bottom = 0
  5. Add the Layout > Aspect Ratio Fitter to the Smurf image and set the Aspect Mode to "Height Controls Width" and the Aspect Ratio to the desired value (16/9 for example)

Check the image : Parent called "Mask" and your smurf image called "Image"

enter image description here

For portrait images, the RectTransform values :

  • Anchors Min = (0, 0.5),
  • Anchors Max = (1, 0.5)
  • Left = 0
  • Right = 0

The Aspect Mode of the child must be set to "Width Controls Heigh"