---
title: 座標與邊界框
url: https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates
description: Claude 如何調整影像大小，以及如何處理它為邊界框、點和 UI 元素所回傳的像素座標。
---

Claude 可以定位並標記影像中的區域（例如，回傳表格、表單欄位、圖表元素或 UI 元件的邊界框）。本指南說明 Claude 在處理影像之前如何調整影像大小，以及如何處理它回傳的像素座標，讓邊界框和點能與您的原始影像對齊。

您在 OCR 管線、表單擷取、圖表解析、UI 元素定位，以及任何需要對影像特定區域採取動作的任務中都會需要這些資訊。關於傳送影像、支援的格式以及各模型的解析度限制，請參閱[視覺](https://platform.claude.com/docs/zh-TW/build-with-claude/vision)。

<Note>
  **Claude 在使用絕對像素座標時表現最佳。** 請在提示中明確要求。例如：*「以像素座標回傳每個表格的邊界框，格式為 `[x1, y1, x2, y2]`（左上角與右下角）。」* 當您要求正規化座標時，Claude 的表現不佳，例如：*「回傳介於 `0` 到 `1000` 之間的邊界框座標。」* 請一律要求像素座標，若有需要再於您自己的程式碼中進行正規化。若要以機器可讀的 JSON 而非散文形式取得座標，請使用[結構化輸出](https://platform.claude.com/docs/zh-TW/build-with-claude/structured-outputs)定義結構描述，例如為每個偵測到的元素定義一個包含 `[x1, y1, x2, y2]` 陣列的物件。
</Note>

座標遵循標準影像慣例：原點 `(0, 0)` 位於影像的左上角，x 向右遞增，y 向下遞增。Claude 回傳的座標是 Claude 所看到影像中的像素位置：也就是 Claude 將您的影像調整大小以符合模型原生解析度之後的影像（請參閱 [Claude 如何調整影像大小與填補影像](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#how-claude-resizes-and-pads-images)）。若要取得可直接使用的座標，您可以在上傳前預先調整影像大小，讓座標與您手上的影像一對一對應（請參閱[上傳前調整影像大小](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#resize-your-image-before-uploading)），或是重新縮放 Claude 回傳的座標（請參閱[無法預先調整大小時重新縮放座標](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#rescale-coordinates-when-you-cannot-pre-resize)）。

<Note>
  Claude 的空間推理能力有其限制（請參閱[限制](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#limitations)）。當您在提示中說明預期的座標格式，並在大規模處理前以視覺方式抽查結果時，座標準確度最佳。影像縮小時，小型元素會失去精確度：對於細小目標，請裁切感興趣的區域並傳送裁切後的影像（將回傳的座標加上裁切原點的偏移量），或使用高解析度層級的模型。對於 [PDF 支援](https://platform.claude.com/docs/zh-TW/build-with-claude/pdf-support)，頁面會在伺服器端以您無法控制的尺寸點陣化為影像，因此回傳的座標無法可靠地對應回頁面。若要處理 PDF 內容的座標，請自行將頁面點陣化為影像，並使用預先調整大小的方法。
</Note>

## Claude 如何調整影像大小與填補影像

Claude 會找出同時滿足模型兩項影像限制、且保持長寬比的最大尺寸：

1. **邊長限制：** 任一邊都不超過最大邊長（標準層級為 1568 px，高解析度層級為 2576 px）。
2. **視覺 token 限制：** 影像的 token 成本 `⌈width / 28⌉ × ⌈height / 28⌉` 不超過模型的視覺 token 預算（標準層級為 1568 個 token，高解析度層級為 4784 個）。

請參閱[解析度與 token 成本](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#evaluate-image-size)以了解各模型所屬的層級。

對於幾乎所有的照片和螢幕截圖，決定最終尺寸的是視覺 token 限制。只有在全景圖或長條形手機截圖等狹長影像上，邊長限制才會起主導作用。請使用[參考實作](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#resize-your-image-before-uploading)計算尺寸，而不要手動依邊長縮放：一張 1920×1080 的螢幕截圖會調整為 1456×819，而非 1568×882，若假設適用邊長限制，會讓每個座標明顯偏離目標。

即使任一邊都未超過邊長限制，token 限制也可能觸發調整大小。忽略這一點是座標錯位最常見的原因。例如，以 130 DPI 掃描的 A4 頁面為 1075×1520 像素：兩邊都小於 1568 px，但它需要 `39 × 55 = 2145` 個視覺 token，因此 Claude 會將其調整為 924×1307。

<Note>
  此範例假設使用標準解析度層級的模型。高解析度層級的模型不會調整同一份掃描影像的大小：2145 個 token 在其 4784 個 token 的預算之內，因此它回傳的座標可直接對應到 1075×1520 的原始影像。模型層級列於[解析度與 token 成本](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#evaluate-image-size)。
</Note>

接著，Claude 會將每張影像（無論是否經過調整大小）在底部和右側邊緣填補至下一個 28 像素的倍數（在此範例中，924×1307 會變成 924×1316）。填補區域不含任何內容：Claude 感知的是填補後的影像，但頁面內容永遠只佔據未填補的調整後區域。**請一律以調整後的尺寸進行正規化或重新縮放，而非填補後的尺寸**；以填補後的尺寸相除會使每個座標產生少量的縮放偏差。

## 上傳前調整影像大小

最可靠的方法是在上傳前自行調整影像大小，如此您手上的影像就正是 Claude 所看到的影像，Claude 回傳的座標也無需轉換。

首先確認您的模型屬於哪個解析度層級（請參閱[解析度與 token 成本](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#evaluate-image-size)），並傳入對應的邊長與 token 限制。以下參考實作可計算 Claude 將影像調整至的確切尺寸：

<CodeGroup exclude="shell">
  <CodeGroupItem language="cURL">
    請在程式碼中計算此尺寸。
  </CodeGroupItem>

  <CodeGroupItem language="CLI">
    請在程式碼中計算此尺寸。
  </CodeGroupItem>

  ```python Python
  import math


  def count_image_tokens(width: int, height: int) -> int:
      """Visual tokens consumed by an image: one token per 28x28 pixel patch."""
      return math.ceil(width / 28) * math.ceil(height / 28)


  def resized_size(
      width: int,
      height: int,
      max_edge: int = 1568,
      max_tokens: int = 1568,
  ) -> tuple[int, int]:
      """The size Claude resizes an image to before padding.

      Defaults are for the standard resolution tier. For high-resolution-tier
      models, use max_edge=2576 and max_tokens=4784. Returns (width, height).
      Images that already fit within the limits are returned unchanged.
      """

      def fits(w: int, h: int) -> bool:
          return (
              math.ceil(w / 28) * 28 <= max_edge
              and math.ceil(h / 28) * 28 <= max_edge
              and count_image_tokens(w, h) <= max_tokens
          )

      if fits(width, height):
          return (width, height)
      if height > width:
          resized_h, resized_w = resized_size(height, width, max_edge, max_tokens)
          return (resized_w, resized_h)

      # 沿長邊進行二分搜尋，找出保持長寬比且能容納的
      # 最大尺寸。
      aspect_ratio = width / height
      lo, hi = 1, width  # lo always fits; hi never fits
      while lo + 1 < hi:
          mid = (lo + hi) // 2
          if fits(mid, max(round(mid / aspect_ratio), 1)):
              lo = mid
          else:
              hi = mid
      return (lo, max(round(lo / aspect_ratio), 1))


  # 「Claude 如何調整大小並填補影像」中的 A4 範例：
  print(resized_size(1075, 1520))  # (924, 1307)

  # 若要套用調整大小，請使用您的影像函式庫，例如 Pillow：
  # image.resize(resized_size(*image.size))
  ```

  ```typescript TypeScript
  /** Visual tokens consumed by an image: one token per 28x28 pixel patch. */
  function countImageTokens(width: number, height: number): number {
    return Math.ceil(width / 28) * Math.ceil(height / 28);
  }

  /**
   * Round half to even (banker's rounding), matching Python's round(). The
   * live API resolves exact .5 ties toward the even neighbor, so Math.round
   * (which rounds halves up) would compute a different size for some images.
   */
  function roundTiesToEven(value: number): number {
    const floor = Math.floor(value);
    if (value - floor !== 0.5) {
      return Math.round(value);
    }
    return floor % 2 === 0 ? floor : floor + 1;
  }

  /**
   * The size Claude resizes an image to before padding.
   *
   * Defaults are for the standard resolution tier. For high-resolution-tier
   * models, use maxEdge = 2576 and maxTokens = 4784. Returns [width, height].
   * Images that already fit within the limits are returned unchanged.
   */
  function resizedSize(
    width: number,
    height: number,
    maxEdge = 1568,
    maxTokens = 1568
  ): [number, number] {
    const fits = (w: number, h: number): boolean =>
      Math.ceil(w / 28) * 28 <= maxEdge &&
      Math.ceil(h / 28) * 28 <= maxEdge &&
      countImageTokens(w, h) <= maxTokens;

    if (fits(width, height)) {
      return [width, height];
    }
    if (height > width) {
      const [resizedH, resizedW] = resizedSize(height, width, maxEdge, maxTokens);
      return [resizedW, resizedH];
    }

    // 沿長邊進行二分搜尋，找出保持長寬比且能容納的
    // 最大尺寸。
    const aspectRatio = width / height;
    let lo = 1; // lo always fits
    let hi = width; // hi never fits
    while (lo + 1 < hi) {
      const mid = Math.floor((lo + hi) / 2);
      if (fits(mid, Math.max(roundTiesToEven(mid / aspectRatio), 1))) {
        lo = mid;
      } else {
        hi = mid;
      }
    }
    return [lo, Math.max(roundTiesToEven(lo / aspectRatio), 1)];
  }

  // 「Claude 如何調整大小與填補影像」中的 A4 範例：
  console.log(resizedSize(1075, 1520)); // [ 924, 1307 ]

  // 若要套用調整大小，請使用您的影像程式庫，例如 sharp：
  // await sharp(input).resize(width, height).toBuffer()
  ```

  ```csharp C#
  // 影像消耗的視覺 token 數：每個 28x28 像素區塊對應一個 token。
  static int CountImageTokens(int width, int height)
  {
      return (width + 27) / 28 * ((height + 27) / 28); // ceil(w/28) * ceil(h/28)
  }

  // Claude 在填補前將影像調整到的大小。預設值適用於
  // 標準解析度層級；若為高解析度層級模型，請傳入
  // maxEdge: 2576, maxTokens: 4784。已符合限制的影像
  // 會原樣回傳。
  static (int Width, int Height) ResizedSize(
      int width, int height, int maxEdge = 1568, int maxTokens = 1568)
  {
      bool Fits(int w, int h) =>
          (w + 27) / 28 * 28 <= maxEdge
          && (h + 27) / 28 * 28 <= maxEdge
          && CountImageTokens(w, h) <= maxTokens;

      if (Fits(width, height))
      {
          return (width, height);
      }
      if (height > width)
      {
          (int resizedH, int resizedW) = ResizedSize(height, width, maxEdge, maxTokens);
          return (resizedW, resizedH);
      }

      // 沿長邊進行二分搜尋，找出能容納且保持長寬比的
      // 最大尺寸。短邊採四捨五入至偶數，與即時 API 在
      // 恰為 .5 時的行為一致（MidpointRounding.ToEven，即 Math.Round 預設）。
      double aspectRatio = (double)width / height;
      int lo = 1; // lo always fits
      int hi = width; // hi never fits
      while (lo + 1 < hi)
      {
          int mid = (lo + hi) / 2;
          if (Fits(mid, ShortEdge(mid)))
          {
              lo = mid;
          }
          else
          {
              hi = mid;
          }
      }
      return (lo, ShortEdge(lo));

      int ShortEdge(int longEdge) =>
          Math.Max((int)Math.Round(longEdge / aspectRatio, MidpointRounding.ToEven), 1);
  }

  // 「Claude 如何調整影像大小與填補」中的 A4 範例：
  Console.WriteLine(ResizedSize(1075, 1520)); // (924, 1307)
  ```

  ```go Go
  // countImageTokens 是一張圖片消耗的視覺 token 數：每個
  // 28x28 像素區塊對應一個 token。
  func countImageTokens(width, height int) int {
  	return ((width + 27) / 28) * ((height + 27) / 28) // ceil(w/28) * ceil(h/28)
  }

  // resizedSize 是 Claude 在填充前將圖片調整到的尺寸，以
  // (width, height) 表示。標準解析度層級請傳入 maxEdge 1568 與 maxTokens 1568，
  // 高解析度層級則傳入 2576 與 4784。已符合
  // 限制的圖片會原樣回傳。
  // 「Claude 如何調整圖片大小與填充」中的 A4 範例：
  // resizedSize(1075, 1520, 1568, 1568) 回傳 (924, 1307)。
  func resizedSize(width, height, maxEdge, maxTokens int) (int, int) {
  	fits := func(w, h int) bool {
  		return ((w+27)/28)*28 <= maxEdge &&
  			((h+27)/28)*28 <= maxEdge &&
  			countImageTokens(w, h) <= maxTokens
  	}

  	if fits(width, height) {
  		return width, height
  	}
  	if height > width {
  		resizedH, resizedW := resizedSize(height, width, maxEdge, maxTokens)
  		return resizedW, resizedH
  	}

  	// 沿長邊進行二分搜尋，找出保持長寬比且能容納的
  	// 最大尺寸。短邊採四捨六入五成雙（math.RoundToEven），
  	// 與即時 API 在恰好 .5 時的行為一致；math.Round 則會進位。
  	aspectRatio := float64(width) / float64(height)
  	lo, hi := 1, width // lo always fits; hi never fits
  	for lo+1 < hi {
  		mid := (lo + hi) / 2
  		short := max(int(math.RoundToEven(float64(mid)/aspectRatio)), 1)
  		if fits(mid, short) {
  			lo = mid
  		} else {
  			hi = mid
  		}
  	}
  	return lo, max(int(math.RoundToEven(float64(lo)/aspectRatio)), 1)
  }
  ```

  ```java Java
  /** A resized image size, as returned by resizedSize. */
  record Size(int width, int height) {}

  /** Visual tokens consumed by an image: one token per 28x28 pixel patch. */
  static int countImageTokens(int width, int height) {
      return Math.ceilDiv(width, 28) * Math.ceilDiv(height, 28);
  }

  /**
   * The size Claude resizes an image to before padding.
   *
   * <p>Pass maxEdge 1568 and maxTokens 1568 for the standard resolution tier,
   * or 2576 and 4784 for the high-resolution tier. Images that already fit
   * within the limits are returned unchanged.
   *
   * <p>The A4 example from "How Claude resizes and pads images":
   * resizedSize(1075, 1520, 1568, 1568) returns new Size(924, 1307).
   */
  static Size resizedSize(int width, int height, int maxEdge, int maxTokens) {
      if (fits(width, height, maxEdge, maxTokens)) {
          return new Size(width, height);
      }
      if (height > width) {
          Size rotated = resizedSize(height, width, maxEdge, maxTokens);
          return new Size(rotated.height(), rotated.width());
      }

      // 沿長邊進行二分搜尋，找出能容納且保持長寬比的
      // 最大尺寸。短邊採用四捨六入五成雙（Math.rint），
      // 與即時 API 在恰好 .5 時的行為一致；Math.round 則會向上取整。
      double aspectRatio = (double) width / height;
      int lo = 1; // lo always fits
      int hi = width; // hi never fits
      while (lo + 1 < hi) {
          int mid = (lo + hi) / 2;
          if (fits(mid, shortEdge(mid, aspectRatio), maxEdge, maxTokens)) {
              lo = mid;
          } else {
              hi = mid;
          }
      }
      return new Size(lo, shortEdge(lo, aspectRatio));
  }

  private static boolean fits(int width, int height, int maxEdge, int maxTokens) {
      return Math.ceilDiv(width, 28) * 28 <= maxEdge
              && Math.ceilDiv(height, 28) * 28 <= maxEdge
              && countImageTokens(width, height) <= maxTokens;
  }

  private static int shortEdge(int longEdge, double aspectRatio) {
      return Math.max((int) Math.rint(longEdge / aspectRatio), 1);
  }
  ```

  ```php PHP
  // 影像消耗的視覺 token 數：每個 28x28 像素區塊對應一個 token。
  function countImageTokens(int $width, int $height): int
  {
      return intdiv($width + 27, 28) * intdiv($height + 27, 28);
  }

  /**
   * The size Claude resizes an image to before padding, as [width, height].
   *
   * Defaults are for the standard resolution tier. For high-resolution-tier
   * models, pass maxEdge: 2576, maxTokens: 4784. Images that already fit
   * within the limits are returned unchanged.
   */
  function resizedSize(int $width, int $height, int $maxEdge = 1568, int $maxTokens = 1568): array
  {
      $fits = fn (int $w, int $h): bool =>
          intdiv($w + 27, 28) * 28 <= $maxEdge
          && intdiv($h + 27, 28) * 28 <= $maxEdge
          && countImageTokens($w, $h) <= $maxTokens;

      if ($fits($width, $height)) {
          return [$width, $height];
      }
      if ($height > $width) {
          [$resizedH, $resizedW] = resizedSize($height, $width, $maxEdge, $maxTokens);
          return [$resizedW, $resizedH];
      }

      // 沿長邊進行二分搜尋，找出能容納且保持長寬比的
      // 最大尺寸。短邊採用四捨六入五成雙
      // （PHP_ROUND_HALF_EVEN），與即時 API 在恰好 .5 平手時的行為一致。
      $aspectRatio = $width / $height;
      $lo = 1; // lo always fits
      $hi = $width; // hi never fits
      while ($lo + 1 < $hi) {
          $mid = intdiv($lo + $hi, 2);
          $short = max((int) round($mid / $aspectRatio, 0, PHP_ROUND_HALF_EVEN), 1);
          if ($fits($mid, $short)) {
              $lo = $mid;
          } else {
              $hi = $mid;
          }
      }

      return [$lo, max((int) round($lo / $aspectRatio, 0, PHP_ROUND_HALF_EVEN), 1)];
  }

  // 來自「Claude 如何調整影像大小與填補」的 A4 範例：
  [$resizedWidth, $resizedHeight] = resizedSize(1075, 1520);
  echo "({$resizedWidth}, {$resizedHeight})\n"; // (924, 1307)
  ```

  ```ruby Ruby
  # 影像消耗的視覺 token：每個 28x28 像素區塊對應一個 token。
  def count_image_tokens(width, height)
    width.ceildiv(28) * height.ceildiv(28)
  end

  # Claude 在填補前將影像調整到的尺寸，格式為 [width, height]。
  #
  # 預設值適用於標準解析度層級。對於高解析度層級
  # 模型，請傳入 max_edge: 2576, max_tokens: 4784。已符合
  # 限制的影像會原樣回傳。
  def resized_size(width, height, max_edge = 1568, max_tokens = 1568)
    fits = lambda do |w, h|
      w.ceildiv(28) * 28 <= max_edge &&
        h.ceildiv(28) * 28 <= max_edge &&
        count_image_tokens(w, h) <= max_tokens
    end

    return [width, height] if fits.call(width, height)

    if height > width
      resized_h, resized_w = resized_size(height, width, max_edge, max_tokens)
      return [resized_w, resized_h]
    end

    # 沿長邊進行二分搜尋，找出保持長寬比且能容納的
    # 最大尺寸。短邊將半值捨入至偶數（round(half: :even)），
    # 在恰好為 .5 的平手情況下與實際 API 一致。
    aspect_ratio = width.fdiv(height)
    lo = 1      # lo always fits
    hi = width  # hi never fits
    while lo + 1 < hi
      mid = (lo + hi) / 2
      short = [(mid / aspect_ratio).round(half: :even), 1].max
      if fits.call(mid, short)
        lo = mid
      else
        hi = mid
      end
    end

    [lo, [(lo / aspect_ratio).round(half: :even), 1].max]
  end

  # 來自「How Claude resizes and pads images」的 A4 範例：
  p resized_size(1075, 1520) # => [924, 1307]
  ```
</CodeGroup>

1. 將影像調整為調整大小輔助函式所回傳的尺寸。如果影像已符合模型的限制，輔助函式會原封不動地回傳其尺寸，無需調整大小。
2. [將調整後的影像傳送](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#send-images-to-claude)至 API。請勿自行填補。Claude 會處理填補，且填補不會移動座標原點。
3. 在提示中明確要求像素座標。例如：*「以像素座標回傳 Submit 按鈕的點擊位置，格式為 `[x, y]`。」*
4. 直接將回傳的座標用於您所傳送的影像。如果您需要正規化座標，請以您所傳送影像的尺寸相除，而非原始影像的尺寸，也非填補後的尺寸。

<Note>
  [Token 計數](https://platform.claude.com/docs/zh-TW/build-with-claude/token-counting)端點會根據影像尺寸估算其 token 成本，而不會完整處理影像，因此計數成功並不代表影像符合 Messages API 的[請求限制](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#request-limits)。影像可能計數成功，但在您傳送時仍遭拒絕。
</Note>

## 使用 `transformations` 將調整大小轉為錯誤

預先調整大小只有在您的管線持續產生正確尺寸時才能保護您的座標。新的影像來源或切換至不同解析度層級的模型，都可能悄悄地重新引入伺服器端的調整大小。若要將這種無聲的偏移轉為可見的錯誤，請在 [Messages](https://platform.claude.com/docs/zh-TW/api/messages) 請求中的影像內容區塊上設定選用的 `transformations` 欄位：

```json
{
  "type": "image",
  "source": { "type": "base64", "media_type": "image/png", "data": "..." },
  "transformations": { "oversized_image": "error" }
}
```

若請求中已標記的影像（任何設定了 `"oversized_image": "error"` 的區塊）會被調整大小，該請求會以 400 `invalid_request_error` 遭拒，錯誤訊息會指出影像的尺寸以及可容納的最大尺寸。影像是否觸發拒絕，取決於[請求中指定的每個模型的限制](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#how-claude-resizes-and-pads-images)：下方 1920×1080 的範例會被標準層級模型拒絕，但符合高解析度層級的限制：

```text wrap
messages.0.content.0: image dimensions 1920x1080 exceed the maximum image size of a model named on this request and would be downsized to 1456x819; scale the image to at most 1456x819 or set the image's oversized_image setting to "downsize"
```

請重新縮放至回報的目標尺寸後重新傳送：該目標是在您影像的長寬比下，請求中指定的每個模型都能接受的最大尺寸。已標記影像與[伺服器端備援 beta](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#server-side-fallback) 的互動方式於該功能中說明；在任何模式下，已標記的影像都絕不會以調整大小後的形式提供。

此設定是針對每張影像的。`"oversized_image": "downsize"`（省略該欄位時的預設值）會維持本頁所述的自動調整大小。每個影像區塊只會依其自身的設定進行檢查，因此同一個請求可以混合尺寸具關鍵意義的影像（您將點擊的螢幕截圖）與調整大小無妨的影像（標誌）。此設定會改變與不會改變的事項：

* 填補（[永遠不會捨棄內容](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#how-claude-resizes-and-pads-images)）、格式轉換與方向校正照常進行。
* 硬性限制（最長邊 8000 px，以及[多影像請求](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#request-limits)中更嚴格的每張影像限制）屬於另外的拒絕條件；此設定絕不會讓影像繞過這些限制。
* 以 URL 或檔案 ID 提供的影像會在其位元組擷取完成後進行檢查；這些拒絕帶有相同的訊息，但沒有開頭的位置資訊，因此無法識別是哪張影像失敗；只有內嵌的 base64 影像會在錯誤中以位置標示。
* [PDF 頁面](https://platform.claude.com/docs/zh-TW/build-with-claude/pdf-support)會在伺服器端以您無法控制的尺寸點陣化；`document` 區塊不接受此欄位（巢狀於文件內容中的影像區塊則與其他影像區塊一樣接受此欄位）。
* 無法判定尺寸的已標記影像會遭拒絕，而非直接放行：該拒絕會回報無法判定影像的來源尺寸，而非上方引述的調整大小訊息。任何設定了 `"error"` 的影像都不會以調整大小後的形式送達模型。

[Token 計數](https://platform.claude.com/docs/zh-TW/build-with-claude/token-counting)端點同樣遵循 `transformations`，會以與 Messages API 完全相同的方式拒絕內嵌圖片，因此您可以在執行推論之前，檢查內嵌圖片是否能在不調整大小的情況下符合限制。計數端點會直接拒絕透過 URL 或檔案 ID 提供的圖片，而不會擷取它們，因此來自這些來源的被標記圖片只會在呼叫 Messages 時進行檢查。

## 無法預先調整大小時重新縮放座標

如果您無法預先調整大小（例如，影像來自您無法修改的上游系統），請使用[上傳前調整影像大小](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#resize-your-image-before-uploading)中的調整大小輔助函式來還原 Claude 所看到的尺寸，然後將 Claude 回傳的座標對應為正規化座標，或對應回您的原始影像。除非影像[選擇改為回傳錯誤](https://platform.claude.com/docs/zh-TW/build-with-claude/vision-coordinates#oversized-image-error)，否則在 API 的[請求限制](https://platform.claude.com/docs/zh-TW/build-with-claude/vision#request-limits)範圍內，Claude 會調整過大影像的大小而非拒絕它們。超出這些限制時，請求會改以驗證錯誤失敗。請傳入與您所呼叫模型相符的層級限制：錯誤層級的限制會還原出錯誤的調整後尺寸，並悄悄地使每個座標偏移。此方法需要知道您所上傳影像的像素尺寸，因此不適用於 PDF 上傳。

您回傳給[電腦使用](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/computer-use-tool#handle-coordinate-scaling-for-higher-resolutions)與[瀏覽器使用](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/browser-use-tool#targets-and-coordinates)工具集的螢幕截圖與縮放影像是自動調整大小的例外。API 會以驗證錯誤拒絕超出模型限制的 `tool_result` 影像，而非調整其大小。請在回傳之前於您的應用程式中調整這些影像的大小，然後將 Claude 回傳的座標縮放回您螢幕的尺寸。

<CodeGroup exclude="shell">
  <CodeGroupItem language="cURL">
    請在程式碼中轉換座標。
  </CodeGroupItem>

  <CodeGroupItem language="CLI">
    請在程式碼中轉換座標。
  </CodeGroupItem>

  ```python Python
  # 此輔助函式呼叫本頁調整大小範例中的 resized_size。
  def to_relative_coordinates(
      x: float,
      y: float,
      original_width: int,
      original_height: int,
      max_edge: int = 1568,
      max_tokens: int = 1568,
  ) -> tuple[float, float]:
      """Map a pixel coordinate returned by Claude to relative coordinates in [0, 1].

      Pass the dimensions of the image you uploaded. For high-resolution-tier
      models, use max_edge=2576 and max_tokens=4784.
      """
      resized_w, resized_h = resized_size(
          original_width, original_height, max_edge, max_tokens
      )
      return (x / resized_w, y / resized_h)


  # Claude 在調整大小後的 A4 頁面上回傳位於 (462, 653.5) 的表格角落，
  # 對應回 1075x1520 原始影像的方式如下：
  rel_x, rel_y = to_relative_coordinates(462, 653.5, 1075, 1520)
  print((rel_x * 1075, rel_y * 1520))  # (537.5, 760.0)
  ```

  ```typescript TypeScript
  // 此輔助函式會呼叫本頁調整大小範例中的 resizedSize。
  /**
   * Map a pixel coordinate returned by Claude to relative coordinates in [0, 1].
   *
   * Pass the dimensions of the image you uploaded. For high-resolution-tier
   * models, use maxEdge = 2576 and maxTokens = 4784.
   */
  function toRelativeCoordinates(
    x: number,
    y: number,
    originalWidth: number,
    originalHeight: number,
    maxEdge = 1568,
    maxTokens = 1568
  ): [number, number] {
    const [resizedW, resizedH] = resizedSize(originalWidth, originalHeight, maxEdge, maxTokens);
    return [x / resizedW, y / resizedH];
  }

  // Claude 在調整大小後的 A4 頁面上回傳位於 (462, 653.5) 的表格角落，
  // 對應回 1075x1520 原始影像的方式如下：
  const [relX, relY] = toRelativeCoordinates(462, 653.5, 1075, 1520);
  console.log([relX * 1075, relY * 1520]); // [ 537.5, 760 ]
  ```

  ```csharp C#
  // 此輔助函式呼叫本頁調整大小範例中的 ResizedSize。
  // 將 Claude 回傳的像素座標對應至 [0, 1] 範圍的
  // 相對座標。請傳入您上傳影像的尺寸，以及與
  // ResizedSize 所用相同的層級限制。
  static (double X, double Y) ToRelativeCoordinates(
      double x, double y, int originalWidth, int originalHeight,
      int maxEdge = 1568, int maxTokens = 1568)
  {
      (int resizedW, int resizedH) =
          ResizedSize(originalWidth, originalHeight, maxEdge, maxTokens);
      return (x / resizedW, y / resizedH);
  }

  // Claude 在調整大小後的 A4 頁面上回傳位於 (462, 653.5) 的表格角落，
  // 對應回 1075x1520 原圖的方式如下：
  (double relX, double relY) = ToRelativeCoordinates(462, 653.5, 1075, 1520);
  Console.WriteLine((relX * 1075, relY * 1520)); // (537.5, 760)
  ```

  ```go Go
  // 此輔助函式呼叫本頁調整大小範例中的 resizedSize。

  // toRelativeCoordinates 將 Claude 回傳的像素座標對應到
  // [0, 1] 範圍內的相對座標。請傳入您上傳圖片的
  // 尺寸，以及與 resizedSize 相同的層級限制。
  func toRelativeCoordinates(
  	x, y float64,
  	originalWidth, originalHeight, maxEdge, maxTokens int,
  ) (float64, float64) {
  	resizedW, resizedH := resizedSize(originalWidth, originalHeight, maxEdge, maxTokens)
  	return x / float64(resizedW), y / float64(resizedH)
  }

  // 若要對應回原始圖片的像素空間，請乘以原始
  // 尺寸：調整後 A4 頁面上回傳於 (462, 653.5) 的表格角落
  // 在 1075x1520 原圖上為 (relX*1075, relY*1520) = (537.5, 760)。
  ```

  ```java Java
  // 此輔助函式呼叫本頁調整大小範例中的 resizedSize。
  /** A coordinate scaled into the [0, 1] range on both axes. */
  record RelativeCoordinate(double x, double y) {}

  /**
   * Map a pixel coordinate returned by Claude to relative coordinates in
   * [0, 1]. Pass the dimensions of the image you uploaded, and the same tier
   * limits used for resizedSize.
   */
  static RelativeCoordinate toRelativeCoordinates(
          double x, double y, int originalWidth, int originalHeight, int maxEdge, int maxTokens) {
      Size resized = resizedSize(originalWidth, originalHeight, maxEdge, maxTokens);
      return new RelativeCoordinate(x / resized.width(), y / resized.height());
  }

  // 若要映射回原始影像的像素空間，請乘以原始
  // 尺寸：在調整大小後的 A4 頁面上回傳於 (462, 653.5) 的表格角點，
  // 在 1075x1520 的原圖上即為 (relative.x() * 1075, relative.y() * 1520)
  // = (537.5, 760)。
  ```

  ```php PHP
  // 此輔助函式呼叫本頁調整大小範例中的 resizedSize()。
  /**
   * Map a pixel coordinate returned by Claude to relative coordinates in
   * [0, 1], as [x, y]. Pass the dimensions of the image you uploaded, and the
   * same tier limits used for resizedSize.
   */
  function toRelativeCoordinates(
      float $x,
      float $y,
      int $originalWidth,
      int $originalHeight,
      int $maxEdge = 1568,
      int $maxTokens = 1568,
  ): array {
      [$resizedW, $resizedH] = resizedSize($originalWidth, $originalHeight, $maxEdge, $maxTokens);

      return [$x / $resizedW, $y / $resizedH];
  }

  // Claude 在調整大小後的 A4 頁面上回傳位於 (462, 653.5) 的表格角落，
  // 對應回 1075x1520 原始影像的方式如下：
  [$relX, $relY] = toRelativeCoordinates(462, 653.5, 1075, 1520);
  echo '(' . $relX * 1075 . ', ' . $relY * 1520 . ")\n"; // (537.5, 760)
  ```

  ```ruby Ruby
  # 此輔助函式會呼叫本頁調整大小範例中的 resized_size。
  # 將 Claude 回傳的像素座標對應到 [0, 1] 範圍內的相對座標，
  # 格式為 [x, y]。請傳入您上傳影像的尺寸，以及
  # 與 resized_size 相同的層級限制。
  def to_relative_coordinates(
    x, y, original_width, original_height, max_edge = 1568, max_tokens = 1568
  )
    resized_w, resized_h = resized_size(original_width, original_height, max_edge, max_tokens)
    [x.fdiv(resized_w), y.fdiv(resized_h)]
  end

  # Claude 在調整大小後的 A4 頁面上回傳位於 (462, 653.5) 的表格角落，
  # 對應回 1075x1520 原圖的方式如下：
  rel_x, rel_y = to_relative_coordinates(462, 653.5, 1075, 1520)
  p [rel_x * 1075, rel_y * 1520] # => [537.5, 760.0]
  ```
</CodeGroup>

填補只套用於底部和右側邊緣，因此原點不會移動，逐軸的線性重新縮放即已足夠。請在重新縮放之前將回傳的座標限制在調整後的尺寸範圍內，如此稍微超出影像的點就不會對應到您原始影像之外。

相對座標可與您所操作的任何表面相乘：原始影像、全解析度掃描影像或螢幕。當您在螢幕上操作，且螢幕截圖像素與邏輯座標不同時（HiDPI 顯示器），還需除以顯示縮放係數。[電腦使用工具的縮放指引](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/computer-use-tool#handle-coordinate-scaling-for-higher-resolutions)涵蓋了該模式。

## 後續步驟

<CardGroup cols={2}>
  <Card title="Agent Skills" icon="stack" href="https://platform.claude.com/docs/zh-TW/agents-and-tools/agent-skills/overview">
    Agent Skills 是擴充 Claude 功能的模組化能力。每個 Skill 都封裝了指令、中繼資料與選用資源（腳本、範本），Claude 會在相關時自動使用。
  </Card>

  <Card title="電腦使用工具" icon="computer" href="https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/computer-use-tool">
    透過電腦使用工具，讓 Claude 取得桌面環境的螢幕截圖、滑鼠與鍵盤控制權。
  </Card>

  <Card title="PDF 支援" icon="file" href="https://platform.claude.com/docs/zh-TW/build-with-claude/pdf-support">
    使用 Claude 處理 PDF。從您的文件中擷取文字、分析圖表並理解視覺內容。
  </Card>

  <Card title="Token 計數" icon="calculator" href="https://platform.claude.com/docs/zh-TW/build-with-claude/token-counting">
    在將訊息傳送給 Claude 之前計算其中的 token 數量。使用 token 計數來管理速率限制與成本、做出模型路由決策，並使提示符合目標長度。
  </Card>
</CardGroup>
