
API 設計原理:從理論到實踐
主要功能:
動機與價值:
注冊并登錄 MIT?App?Inventor:
新建項目:
GenAIDigitalDoodle
,點擊 OK。從 Drawing and Animation 拖入 Canvas
,設置:
SEO 注入:在本文圖片 Alt 中添加:
< img src="..." alt="GenAI Digital Doodle App 界面,展示 MIT App Inventor Canvas 繪圖和 AI 背景" >
HorizontalArrangement
,Width 設為 Fill parent,AlignHorizontal 設為 Center;在橫向布局內依次添加 4 個 Button
:
BlackButton
,BackgroundColor?= Black,TextColor?= Yellow,Text?= BlackRedButton
,BackgroundColor?= Red,TextColor?= White,Text?= RedBlueButton
,BackgroundColor?= Blue,TextColor?= White,Text?= BlueGreenButton
,BackgroundColor?= Green,TextColor?= White,Text?= Green在 User Interface 拖入 Slider
,設置:
Label
,Text?= “Type in your background”,AlignHorizontal?= Center;TextBox
,Rename?= GenAITextBox,Width?= Fill parent;Button
,Rename?= GenAIButton,Text?= “Generate Background”,BackgroundColor?= Orange,Shape?= Rounded;when Canvas1.Dragged
Canvas1.SetLineWidth to Slider1.ThumbPosition
繪制線段: Canvas1.DrawLine get prevX, get prevY, get currentX, get currentY
prevX/prevY
而非 startX/startY
,以實現平滑的連續曲線。when AccelerometerSensor1.Shaking
清空畫布: Canvas1.Clear
分別在 when BlackButton.Click
、when RedButton.Click
、when BlueButton.Click
、when GreenButton.Click
中:
set Canvas1.PaintColor to colors.Black/Red/Blue/Green
點擊生成按鈕
when GenAIButton.Click
call Notifier1.ShowProgressDialog message="Generating Image" title="Please Wait"
call ImageBot1.CreateImage description=GenAITextBox.Text
AI 圖像生成回調
when ImageBot1.ImageCreated
call Notifier1.DismissProgressDialog
set Canvas1.BackgroundImage to get fileName
Canvas1.Dragged
進行節流,防止過快觸發 DrawLine 導致卡頓;更多 AI 能力接入
細粒度擦除與圖層管理
社交與在線畫廊
硬件擴展
本文以一款基于 MIT?App?Inventor 的 GenAI?Digital?Doodle 應用為實踐案例,深入演示了如何結合 Canvas?繪圖、Accelerometer?搖一搖擦除、滑塊調節線寬、按鈕切換顏色 與 Google?Doodle?AI 圖像互動 API(ImageBot1.CreateImage)等組件,實現一款功能豐富、交互多元、易于擴展的數字涂鴉應用。希望本文能幫助你快速上手 Android 端 生成式 AI 背景生成、圖像互動 API 等前沿技術,開啟更多創意十足的交互式 AI 應用開發之旅!
原文引自YouTube視頻:https://www.youtube.com/watch?v=0fDcE2a3zdU