Community图像github.com

screenshot-to-compose (截图转Compose)

将应用设计截图(JPG/PNG,通常由AI生成)或Figma框架转换为精确匹配的Kotlin Jetpack Compose原生UI。以设计优先,测量像素和颜色(px到dp),编写屏幕/素材清单和设计系统,对比渲染结果与参考图。

screenshot-to-compose (截图转Compose) 是什么?

此技能专为将设计截图或Figma框架忠实地转化为Android Compose UI而设计。它通过系统化的流程(检查、清点、测量、设计系统、素材、规划、实现、对比、交付)确保UI像素级匹配设计稿。核心在于精确测量(px转dp)、分离观察值与推断值、使用Iconify图标并生成素材(而非裁剪截图),最终通过并排比对来验证。支持平台包括Claude Code、Cursor、Codex等AI代理工具,开发者只需提供截图或提出“在Compose中实现这个界面”等要求,技能便会从零搭建完整MVI架构的屏幕。该技能规则严格,禁止裁剪参考图、禁止用图片替代原生UI、禁止在无明确设计时臆造设计,确保输出高质量、可维护的Compose代码。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/zohaibmushwani/agent-skills/tree/HEAD/skills/screenshot-to-compose

Installed? Explore more 图像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

screenshot-to-compose (截图转Compose) 是做什么的?

在不凭肉眼估计的情况下,在 Compose 中忠实复现设计。参考图像就是验收测试,因此你使用的每个数字要么是 观察值(在图像上测量得到),要么是 推断值(你明确的猜测),最终完成的屏幕会与参考图进行比对。

当设计作为输入时

  • 仅有截图/设计稿:遵循以下所有阶段。
  • 有 Figma 框架可用:跳过测量步骤(从 Figma 读取数值),保留其余步骤。
  • 尚无设计:先使用 app-design-studio 技能,然后再回到此处。

工作流程

在 docs/design/ 目录下按文件操作,一次一个屏幕,先完成共享基础。不要在任何东西都未理解之前就实现整个屏幕清单。

  1. 检查。 先阅读仓库(架构、主题、共享组件、现有屏幕)。保留可用部分。记录假设。
  2. 清点。 将参考图原样复制到 docs/design/reference/ 目录(使用 kebab-case 命名)。编写 SCREEN_INVENTORY.md:每个图片 -> 屏幕+状态、屏幕间链接、缺失的参考(有链接但未显示的屏幕)、像素尺寸和宽高比。包含每种状态:加载、空、错误、离线、权限、高级。
  3. 测量。 运行 scripts/measure_image.py shot.png --frame-dp 390 --sample x,y ... 获取 px->dp 的比例和颜色采样(references/measuring.md)。像素不是 dp:除非另有说明,否则假设框架为 390 dp,dp = px / (imageWidthPx / 390)。在单独的列中记录 观察值 和 推断值。
  4. 设计系统。 将测量到的颜色映射到 Material 3 角色、字体缩放比例、形状、间距,并放入主题中。屏幕仅使用主题令牌(屏幕中不允许出现十六进制颜色、尺寸或圆角)。定义亮色和暗色主题;如果只有亮色,则在不改变布局的前提下推导暗色。
  5. 素材(references/assets.md)。图标:选择一套字体,从 Iconify 获取,使用 scripts/svg_to_vectordrawable.py 转换。插画:生成插画,绝不能从截图中裁剪。文本、按钮、卡片、圆环和图表始终使用 Compose 实现,不能使用图片。在 ASSET_INVENTORY.md 中记录来源、许可证、模型和提示词。
  6. 规划。 针对每个屏幕提前决定:返回行为、网络/离线类别、权限、小屏幕上的滚动或适配、动效。编写 SCREEN_IMPLEMENTATION_PLAN.md,包含构建顺序。(这些质量规则在 android-compose-quality-gate 技能中。)
  7. 实现 先实现共享基础,再实现屏幕:使用不可变 UI 状态上的无状态 Composable、带 Intent 的 ViewModel、每个文件一个 Composable、所有文本使用字符串资源。仅在互不冲突的文件之间并行化独立模块。在构建卡片、磁贴或紧凑文本之前,阅读 references/compose-lessons.md。
  8. 对比(references/verification.md)。渲染屏幕(模拟器截图或 Roborazzi),将其与参考图以等宽并排放置,使用 scripts/compare_side_by_side.py 列出布局、间距、字体、颜色、形状和素材方面的差异,修正,重复。然后检查小设备(360 x 526 dp)、长文本/德语、RTL、暗色、字体缩放 1.3。绝不以功能或响应性换取像素匹配。
  9. 交付。 保持参考图、带提示词的素材、图标来源/许可证、清单和对比笔记的最新状态。屏幕只有在正常工作 并且 通过视觉对比后才算完成。按主题提交。

阻止常见失败的规则

  • 绝不能从参考截图中裁剪图像(低分辨率、压缩、UI 内嵌)。
  • 绝不能将原生 UI 替换为其图片。
  • 当参考图不明确时不要发明设计:做出最合理的推断,将其写入推断列,并贴近参考。
  • 在屏幕运行并对比之前,不要声称完成。
  • 仓库或文档中不得包含机密(API 密钥);图片服务密钥来自环境变量。

文件

  • references/measuring.md - px 到 dp、颜色采样、观察值与推断值表格。
  • references/assets.md - Iconify 到 VectorDrawable、图片生成顺序和审查、导出尺寸、其他来源。
  • references/compose-lessons.md - 浪费大量时间的缺陷:兄弟卡片比例、内在测量崩溃、宽度阈值、自动缩放文本。
  • references/verification.md - 模拟器与 Roborazzi 的比对循环及设备矩阵。
  • scripts/measure_image.py、scripts/svg_to_vectordrawable.py、scripts/compare_side_by_side.py(Python 3 + Pillow)。

Individual skills in this repo

This repo contains 2 individual skills — each has its own dedicated page.

app-design-studio

Turn an app name or a website / web-app idea into a complete high-fidelity UI design repository - pages or screens, every state (loading, empty, error, offline), dialogs, sheets, components, interactions - with a locked design system and measurable usability gates. Three targets, each with its own profile and wording - mobile app (portrait screens: splash, onboarding, auth, home, settings), website (landscape desktop pages plus a narrow responsive layout), web app / portal / dashboard. Use whenever the user gives an app name or idea and wants screens, pages, UI design, a design repo, mockups, a screen inventory, or a design to hand to developers/designers, even if they never say "skill" or "Figma". Also use to audit or fix an existing set of generated screens for usability (contrast, targets, states) while keeping them beautiful.

store-screenshots

Create App Store and Google Play marketing screenshot sets that look like top-chart apps - a headline-led story of 5-8 frames with a poster-style first frame, zoomed real UI fragments, a dominant brand colour, panoramic links between frames, social proof and human touches - generated frame by frame with Codex (GPT Image) using the app's real screens as reference images, text-checked and edit-passed, then fitted to the exact store sizes. Use whenever the user wants store screenshots, "App Store screenshots", "Play Store images", listing graphics, a screenshot redesign or "before/after" for a store page, or wants their app's store page to convert better, even if they only say "screenshots" for an app. Takes real app screens (for example from app-design-studio) as input.

相关技能