diff --git a/src/app/page.tsx b/src/app/page.tsx index 97bb26f..35d56fb 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -543,8 +543,34 @@ export default function Home() { if (N <= 0 || M <= 0) { console.error("Invalid grid dimensions:", { N, M }); return; } console.log(`Grid size: ${N}x${M}`); - const outputWidth = 500; + // 动态调整画布尺寸:当格子数量大于100时,增加画布尺寸以保持每个格子的可见性 + const baseWidth = 500; + const minCellSize = 4; // 每个格子的最小尺寸(像素) + const recommendedCellSize = 6; // 推荐的格子尺寸(像素) + + let outputWidth = baseWidth; + + // 如果格子数量大于100,计算需要的画布宽度 + if (N > 100) { + const requiredWidthForMinSize = N * minCellSize; + const requiredWidthForRecommendedSize = N * recommendedCellSize; + + // 使用推荐尺寸,但不超过屏幕宽度的90%(最大1200px) + const maxWidth = Math.min(1200, window.innerWidth * 0.9); + outputWidth = Math.min(maxWidth, Math.max(baseWidth, requiredWidthForRecommendedSize)); + + // 确保不小于最小要求 + outputWidth = Math.max(outputWidth, requiredWidthForMinSize); + + console.log(`Large grid detected (${N} columns). Adjusted canvas width from ${baseWidth} to ${outputWidth}px (cell size: ${Math.round(outputWidth / N)}px)`); + } + const outputHeight = Math.round(outputWidth * aspectRatio); + + // 在控制台提示用户画布尺寸变化 + if (N > 100) { + console.log(`💡 由于格子数量较多 (${N}x${M}),画布已自动放大以保持清晰度。可以使用水平滚动查看完整图像。`); + } originalCanvas.width = img.width; originalCanvas.height = img.height; pixelatedCanvas.width = outputWidth; pixelatedCanvas.height = outputHeight; console.log(`Canvas dimensions: Original ${img.width}x${img.height}, Output ${outputWidth}x${outputHeight}`); @@ -1860,8 +1886,19 @@ export default function Home() { {/* Canvas Preview Container */} {/* Apply dark mode styles */}
- {/* Inner container background */} -
100 && ( +
+
+ + + + 高精度网格 ({gridDimensions.N}×{gridDimensions.M}) - 画布已自动放大,可左右滚动、放大查看精细图像 +
+
+ )} + {/* Inner container background - 允许水平滚动以适应大画布 */} +
{/* PixelatedPreviewCanvas component needs internal changes for dark mode drawing */}