學習
引擎類別
CaptureService
無法建立
服務

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


概要

方法
CaptureScreenshot(onCaptureReady: function):()
PromptSaveCapturesToGallery(captures: {any},resultCallback: function):()
PromptShareCapture(captureContent: Content,launchData: string,onAcceptedCallback: function,onDeniedCallback: function):()
ReadCapturesFromGalleryAsync(captureTypeFilters: {any},readFromAllEligibleExperiences: boolean):Tuple
TakeScreenshotCaptureAsync(onCaptureReady: function,captureParams: Dictionary):()
繼承成員

API 參考
方法
CaptureScreenshot
功能: Capture
CaptureService:CaptureScreenshot(onCaptureReady:function):()
參數
onCaptureReady:function
返回
()
範例程式碼
捕捉螢幕截圖
local CaptureService = game:GetService("CaptureService")
-- 參考包含此代碼的腳本的 ImageLabel 父物件
local imageLabel = script.Parent
local function onCaptureReady(contentId)
imageLabel.Image = contentId
end
CaptureService:CaptureScreenshot(onCaptureReady)

CheckUploadCaptureStatusAsync
暫停
功能: Capture
CaptureService:CheckUploadCaptureStatusAsync(token:string):Tuple
參數
token:string
返回

PromptCaptureGalleryPermissionAsync
暫停
功能: Capture
CaptureService:PromptCaptureGalleryPermissionAsync(captureGalleryPermission:Enum.CaptureGalleryPermission):boolean
參數
captureGalleryPermission:Enum.CaptureGalleryPermission
返回
範例程式碼
提示捕捉畫廊權限
local CaptureService = game:GetService("CaptureService")
local function isGalleryAccessGranted()
local accepted = CaptureService:PromptCaptureGalleryPermissionAsync(Enum.CaptureGalleryPermission.ReadAndUpload)
return accepted
end

PromptSaveCapturesToGallery
功能: Capture
CaptureService:PromptSaveCapturesToGallery(
captures:{any}, resultCallback:function
):()
參數
captures:{any}
resultCallback:function
返回
()

PromptShareCapture
功能: Capture
CaptureService:PromptShareCapture(
captureContent:Content, launchData:string, onAcceptedCallback:function, onDeniedCallback:function
):()
參數
captureContent:Content
launchData:string
onAcceptedCallback:function
onDeniedCallback:function
返回
()
範例程式碼
提示分享捕捉
local CaptureService = game:GetService("CaptureService")
local function onShareAccepted()
print("捕捉分享已被接受!")
end
local function onShareDenied()
print("捕捉分享已被拒絕!")
end
local onCaptureReady = function(result, videoCapture)
if videoCapture then
local captureContent = Content.fromObject(videoCapture)
CaptureService:PromptShareCapture(captureContent, "launchData" , onShareAccepted, onShareDenied)
end
end
CaptureService:StartVideoCaptureAsync(onCaptureReady, {})

ReadCapturesFromGalleryAsync
暫停
功能: Capture
CaptureService:ReadCapturesFromGalleryAsync(
captureTypeFilters:{any}, readFromAllEligibleExperiences:boolean
參數
captureTypeFilters:{any}
預設值:"{}"
readFromAllEligibleExperiences:boolean
預設值:false
返回
範例程式碼
從畫廊讀取捕獲並遍歷頁面
local CaptureService = game:GetService("CaptureService")
local function readCapturesFromGallery()
local allCaptures = {}
local capturesPages
local success, result = pcall(function()
local readResult, pages = CaptureService:ReadCapturesFromGalleryAsync({}, false)
if readResult == Enum.ReadCapturesFromGalleryResult.Success then
capturesPages = pages
end
return readResult
end)
if not success or result ~= Enum.ReadCapturesFromGalleryResult.Success then
-- 可能是權限錯誤,請參見 CaptureService:PromptCaptureGalleryPermissionAsync()
warn("無法獲取初始捕獲: " .. result.Name)
return
end
-- 遍歷當前頁面
local currentPage = capturesPages:GetCurrentPage()
for _, capture in currentPage do
table.insert(allCaptures, capture)
end
-- 進入下一頁直到完成
while not capturesPages.IsFinished do
local advanceToNextPageSuccess, _ = pcall(function()
capturesPages:AdvanceToNextPageAsync()
end)
if not advanceToNextPageSuccess then
return
end
currentPage = capturesPages:GetCurrentPage()
for _, capture in currentPage do
table.insert(allCaptures, capture)
end
end
return allCaptures
end

StartUploadCaptureAsync
暫停
功能: Capture
CaptureService:StartUploadCaptureAsync(capture:Capture):Tuple
參數
capture:Capture
返回

StartVideoCaptureAsync
暫停
功能: Capture
CaptureService:StartVideoCaptureAsync(
onCaptureReady:function, captureParams:Dictionary
參數
onCaptureReady:function
captureParams:Dictionary
預設值:"nil"
範例程式碼
開始視頻捕捉異步
local CaptureService = game:GetService("CaptureService")
local tool = Instance.new("Tool")
tool.Parent = workspace
local onCaptureReady = function(result, videoCapture)
if result ~= Enum.VideoCaptureResult.Success and result ~= Enum.VideoCaptureResult.TimeLimitReached or not videoCapture then
print("視頻錄製未能完成,原因:", result)
else
-- 提示用戶將視頻捕捉保存到他們的相冊
CaptureService:PromptSaveCapturesToGallery({ videoCapture }, function()
print("捕捉已保存")
end)
end
end
tool.Activated:Connect(function()
local videoRecordingAllowedResult: Enum.VideoCaptureStartedResult = CaptureService:StartVideoCaptureAsync(onCaptureReady, {})
if videoRecordingAllowedResult ~= Enum.VideoCaptureStartedResult.Success then
print("視頻錄製未能啟動,原因:", videoRecordingAllowedResult)
end
end)

StopVideoCapture
功能: Capture
CaptureService:StopVideoCapture():()
返回
()

TakeScreenshotCaptureAsync
功能: Capture
CaptureService:TakeScreenshotCaptureAsync(
onCaptureReady:function, captureParams:Dictionary
):()
參數
onCaptureReady:function
captureParams:Dictionary
預設值:"nil"
返回
()
範例程式碼
截圖捕捉異步
local CaptureService = game:GetService("CaptureService")
local parent = Instance.new("Tool")
parent.Parent = workspace
local onCaptureReady = function(result, screenshotCapture)
if result ~= Enum.ScreenshotCaptureResult.Success or not screenshotCapture then
print("截圖未能完成,原因:", result)
else
-- 提示用戶將截圖保存到他們的相冊
CaptureService:PromptSaveCapturesToGallery({ screenshotCapture }, function(results)
for capture, result in pairs(results) do
if result then
print("捕捉已保存")
end
end
end)
end
end
parent.Activated:Connect(function()
CaptureService:TakeScreenshotCaptureAsync(onCaptureReady, { UICaptureMode = Enum.UICaptureMode.All })
end)

UploadCaptureAsync
暫停
功能: Capture
CaptureService:UploadCaptureAsync(capture:Capture):Tuple
參數
capture:Capture
返回
範例程式碼
上傳捕捉到資產系統
local CaptureService = game:GetService("CaptureService")
local function uploadCapture(capture: Capture)
local success, result = pcall(function()
local uploadCaptureResult, assetId = CaptureService:UploadCaptureAsync(capture)
if uploadCaptureResult ~= Enum.UploadCaptureResult.Success then
-- 處理失敗
return nil
end
return assetId
end)
if not success then
-- 處理錯誤
return nil
end
return result
end

活動
CaptureBegan
功能: Capture
CaptureService.CaptureBegan(captureType:Enum.CaptureType):RBXScriptSignal
參數
captureType:Enum.CaptureType

CaptureEnded
功能: Capture
CaptureService.CaptureEnded(captureType:Enum.CaptureType):RBXScriptSignal
參數
captureType:Enum.CaptureType

CaptureSaved
已棄用

UserCaptureSaved
功能: Capture
CaptureService.UserCaptureSaved(captureContentId:ContentId):RBXScriptSignal
參數
captureContentId:ContentId

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。