import { useState } from "react"; import { Radio, Select } from "antd"; import { AppModal } from "@/components/ui/product/app-modal"; import { MAX_UPSCALE_LONG_EDGE, resolveUpscaleSize, type ImageUpscaleAlgorithm, type ImageUpscaleParams } from "@/lib/canvas/image-operation-plan"; import { useImageToolSource } from "./use-image-tool-source"; export type CanvasImageUpscaleParams = ImageUpscaleParams; type UpscaleDialogProps = { dataUrl: string; open: boolean; onClose: () => void; onConfirm: (params: CanvasImageUpscaleParams) => void }; const pixelTargets = [1024, 2048, MAX_UPSCALE_LONG_EDGE]; export function CanvasNodeUpscaleDialog(props: UpscaleDialogProps) { return props.open && props.dataUrl ? : null; } function ResizeEditor({ dataUrl, onClose, onConfirm }: UpscaleDialogProps) { const { size, error } = useImageToolSource(dataUrl); const [chosen, setChosen] = useState(null); const [algorithm, setAlgorithm] = useState("high"); const edge = size ? Math.max(size.width, size.height) : 0; const target = chosen ?? pixelTargets.find((pixels) => pixels > edge) ?? MAX_UPSCALE_LONG_EDGE; const output = size ? resolveUpscaleSize(size.width, size.height, target) : null; const ready = Boolean(size && target > edge); return ( ready && onConfirm({ targetLongEdge: target, algorithm })}> 插值放大并另存为新图片,原图保留。此操作不生成新的真实细节。 {size ? `原图 ${size.width} × ${size.height} px` : error || "正在读取图片…"} 目标长边 ({ value: pixels, label: `${pixels} px`, disabled: pixels <= edge }))} /> 插值方式 setAlgorithm(event.target.value)} className="flex flex-col gap-2"> 高质量 · 照片与细节图 双线性 · 平滑快速 最近邻 · 像素图 {output ? `输出 ${output.width} × ${output.height} px` : "等待读取尺寸"} {error || (size && !ready) ? ( {error || (edge >= MAX_UPSCALE_LONG_EDGE ? "图片已达到 4K,无需放大" : "请选择大于原图的目标尺寸")} ) : null} ); }
插值放大并另存为新图片,原图保留。此操作不生成新的真实细节。
{error || (edge >= MAX_UPSCALE_LONG_EDGE ? "图片已达到 4K,无需放大" : "请选择大于原图的目标尺寸")}