You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:添加ARReferenceImage时Xcode自动修改物理尺寸维度的原因

Why Xcode Automatically Adjusts ARReferenceImage Physical Dimensions

Hey there! I’ve run into this exact issue before when working with ARKit image recognition, so let me walk you through what’s happening and how to fix it.

The Core Reason: Pixel Aspect Ratio Mismatch

Xcode adjusts your input dimensions because the physical size you’re entering doesn’t match the pixel aspect ratio of your book photo.

ARKit relies on the relationship between an image’s pixel dimensions and its real-world physical size to accurately recognize and place content. If you input a physical size whose width/height ratio doesn’t align with the photo’s pixel width/height ratio, Xcode automatically adjusts one dimension to enforce this alignment. This ensures ARKit can correctly estimate the image’s position and scale in the real world—without this match, your AR content would appear stretched or misplaced.

For example:

  • Suppose your book photo has a pixel resolution of 1450x2800 (ratio ~0.518:1)
  • If you input a physical width of 14.5cm, Xcode will calculate the height as 14.5 / 0.518 ≈ 28cm (instead of your desired 26.5cm) to match the pixel ratio.

How to Fix It

You have two straightforward solutions to stop Xcode from modifying your dimensions:

1. Calculate and Use Matching Physical Dimensions

  • First, find your photo’s pixel dimensions (right-click the image > Get Info, or check it in Preview).
  • Calculate the pixel aspect ratio: pixel_width / pixel_height
  • Use this ratio to compute the correct physical dimension pair. For your desired 14.5cm width:
    physical_height = physical_width / (pixel_width / pixel_height)
    
  • Input both calculated dimensions into Xcode—since they match the photo’s pixel ratio, Xcode won’t adjust them.

2. Crop Your Photo to Match the Desired Physical Ratio

If you absolutely need the physical size to be 14.5cm × 26.5cm (ratio ~0.547:1), crop your book photo to this exact aspect ratio first. Once the pixel ratio matches the physical size ratio, Xcode will accept your input without changes.

Quick Note on Xcode’s UI

Keep an eye on the small lock icon next to the dimension input fields in Xcode’s ARReferenceImage settings. When locked, changing one dimension automatically adjusts the other to maintain the current ratio. Unlocking it lets you input separate values—but remember, ARKit still requires the final dimensions to match the photo’s pixel ratio, so Xcode will override your input if they don’t align.

内容的提问来源于stack exchange,提问作者Kunal Shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:08:02