Capture Service
摘要
方法
CaptureScreenshot(onCaptureReady: function):() |
CheckUploadCaptureStatusAsync(token: string):Tuple |
PromptCaptureGalleryPermissionAsync(captureGalleryPermission: Enum.CaptureGalleryPermission):boolean |
PromptSaveCapturesToGallery(captures: {any},resultCallback: function):() |
PromptShareCapture(captureContent: Content,launchData: string,onAcceptedCallback: function,onDeniedCallback: function):() |
ReadCapturesFromGalleryAsync(captureTypeFilters: {any},readFromAllEligibleExperiences: boolean):Tuple |
StartUploadCaptureAsync(capture: Capture):Tuple |
StartVideoCaptureAsync(onCaptureReady: function,captureParams: Dictionary):Enum.VideoCaptureStartedResult |
StopVideoCapture():() |
TakeScreenshotCaptureAsync(onCaptureReady: function,captureParams: CaptureParams):() |
UploadCaptureAsync(capture: Capture):Tuple |
活动
CaptureBegan(captureType: Enum.CaptureType):RBXScriptSignal |
CaptureEnded(captureType: Enum.CaptureType):RBXScriptSignal |
CaptureSaved(captureInfo: Dictionary):RBXScriptSignal |
UserCaptureSaved(captureContentId: ContentId):RBXScriptSignal |
API 参考
方法
Capture Screenshot
参数
返回
()
代码示例
捕获屏幕截图
local CaptureService = game:GetService("CaptureService")
-- 引用包含此代码的脚本的 ImageLabel 父级
local imageLabel = script.Parent
local function onCaptureReady(contentId)
imageLabel.Image = contentId
end
CaptureService:CaptureScreenshot(onCaptureReady)Check Upload Capture Status Async
Prompt Capture Gallery Permission Async
Capture Service: Prompt Capture Gallery Permission Async(capture Gallery Permission:Enum.CaptureGalleryPermission):boolean
参数
返回
代码示例
提示用户获取捕获画廊权限
local CaptureService = game:GetService("CaptureService")
local function isGalleryAccessGranted()
local accepted = CaptureService:PromptCaptureGalleryPermissionAsync(Enum.CaptureGalleryPermission.ReadAndUpload)
return accepted
end
print(isGalleryAccessGranted())Prompt Save Captures To Gallery
返回
()
代码示例
提示分享捕获
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, {})Read Captures From Gallery Async
返回
代码示例
从画廊读取捕获并遍历页面
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
local captures = readCapturesFromGallery()
print(captures)Start Upload Capture Async
Start Video Capture Async
Capture Service: Start Video Capture Async(
参数
| 默认值: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)Stop Video Capture
Capture Service: Stop Video Capture():()
返回
()
Take Screenshot Capture Async
参数
captureParams:CaptureParams 默认值: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)Upload Capture Async
参数
返回
代码示例
上传捕捉到资产系统
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
CaptureService:TakeScreenshotCaptureAsync(function(result, screenshotCapture)
if result == Enum.ScreenshotCaptureResult.Success and screenshotCapture then
print(uploadCapture(screenshotCapture))
end
end)活动
Capture Began
参数
Capture Ended
参数
Capture Saved
User Capture Saved
参数
captureContentId:ContentId |