学习
引擎类
CaptureService
无法创建
服务

*此内容使用人工智能(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 是我们在美国及其他国家或地区的注册与未注册商标。