Học
Lớp công cụ
CaptureService
Không Thể Tạo
Dịch Vụ

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Phương Pháp
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):()
Sự Kiện
CaptureSaved(captureInfo: Dictionary):RBXScriptSignal
Đã Lỗi Thời
UserCaptureSaved(captureContentId: ContentId):RBXScriptSignal
Thành viên kế thừa

Tài Liệu Tham Khảo API
Phương Pháp
CaptureScreenshot
Các khả năng: Capture
CaptureService:CaptureScreenshot(onCaptureReady:function):()
Tham Số
onCaptureReady:function
Lợi Nhuận
()
Mẫu mã
Chụp Ảnh Màn Hình
local CaptureService = game:GetService("CaptureService")
-- Tham chiếu đến một ImageLabel cha của script chứa mã này
local imageLabel = script.Parent
local function onCaptureReady(contentId)
imageLabel.Image = contentId
end
CaptureService:CaptureScreenshot(onCaptureReady)

CheckUploadCaptureStatusAsync
Sinh Lợi
Các khả năng: Capture
CaptureService:CheckUploadCaptureStatusAsync(token:string):Tuple
Tham Số
token:string
Lợi Nhuận

PromptCaptureGalleryPermissionAsync
Sinh Lợi
Các khả năng: Capture
CaptureService:PromptCaptureGalleryPermissionAsync(captureGalleryPermission:Enum.CaptureGalleryPermission):boolean
Tham Số
captureGalleryPermission:Enum.CaptureGalleryPermission
Lợi Nhuận
Mẫu mã
Yêu cầu quyền truy cập vào thư viện hình ảnh
local CaptureService = game:GetService("CaptureService")
local function isGalleryAccessGranted()
local accepted = CaptureService:PromptCaptureGalleryPermissionAsync(Enum.CaptureGalleryPermission.ReadAndUpload)
return accepted
end

PromptSaveCapturesToGallery
Các khả năng: Capture
CaptureService:PromptSaveCapturesToGallery(
captures:{any}, resultCallback:function
):()
Tham Số
captures:{any}
resultCallback:function
Lợi Nhuận
()

PromptShareCapture
Các khả năng: Capture
CaptureService:PromptShareCapture(
captureContent:Content, launchData:string, onAcceptedCallback:function, onDeniedCallback:function
):()
Tham Số
captureContent:Content
launchData:string
onAcceptedCallback:function
onDeniedCallback:function
Lợi Nhuận
()
Mẫu mã
Chia sẻ ghi lại
local CaptureService = game:GetService("CaptureService")
local function onShareAccepted()
print("Chia sẻ ghi lại đã được chấp nhận!")
end
local function onShareDenied()
print("Chia sẻ ghi lại đã bị từ chối!")
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
Sinh Lợi
Các khả năng: Capture
CaptureService:ReadCapturesFromGalleryAsync(
captureTypeFilters:{any}, readFromAllEligibleExperiences:boolean
Tham Số
captureTypeFilters:{any}
Giá Trị Mặc Định: "{}"
readFromAllEligibleExperiences:boolean
Giá Trị Mặc Định: false
Lợi Nhuận
Mẫu mã
Đọc các bản chụp từ thư viện và lặp qua các trang
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
-- Có thể là lỗi quyền, xem CaptureService:PromptCaptureGalleryPermissionAsync()
warn("Không thể lấy các bản chụp ban đầu: " .. result.Name)
return
end
-- Lặp qua trang hiện tại
local currentPage = capturesPages:GetCurrentPage()
for _, capture in currentPage do
table.insert(allCaptures, capture)
end
-- Tiến đến trang tiếp theo cho đến khi hoàn tất
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
Sinh Lợi
Các khả năng: Capture
CaptureService:StartUploadCaptureAsync(capture:Capture):Tuple
Tham Số
capture:Capture
Lợi Nhuận

StartVideoCaptureAsync
Sinh Lợi
Các khả năng: Capture
CaptureService:StartVideoCaptureAsync(
onCaptureReady:function, captureParams:Dictionary
Tham Số
onCaptureReady:function
captureParams:Dictionary
Giá Trị Mặc Định: "nil"
Mẫu mã
Bắt đầu ghi video không đồng bộ
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("Ghi video không hoàn thành vì lý do:", result)
else
-- Nhắc nhở người dùng lưu video ghi lại vào thư viện ảnh của họ
CaptureService:PromptSaveCapturesToGallery({ videoCapture }, function()
print("Ghi lại đã được lưu")
end)
end
end
tool.Activated:Connect(function()
local videoRecordingAllowedResult: Enum.VideoCaptureStartedResult = CaptureService:StartVideoCaptureAsync(onCaptureReady, {})
if videoRecordingAllowedResult ~= Enum.VideoCaptureStartedResult.Success then
print("Ghi video không thể bắt đầu vì lý do:", videoRecordingAllowedResult)
end
end)

StopVideoCapture
Các khả năng: Capture
CaptureService:StopVideoCapture():()
Lợi Nhuận
()

TakeScreenshotCaptureAsync
Các khả năng: Capture
CaptureService:TakeScreenshotCaptureAsync(
onCaptureReady:function, captureParams:Dictionary
):()
Tham Số
onCaptureReady:function
captureParams:Dictionary
Giá Trị Mặc Định: "nil"
Lợi Nhuận
()
Mẫu mã
Chụp Ảnh Màn Hình Bất Đồng Bộ
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("Chụp ảnh màn hình không hoàn thành vì lý do:", result)
else
-- Yêu cầu người dùng lưu ảnh chụp màn hình vào thư viện ảnh của họ
CaptureService:PromptSaveCapturesToGallery({ screenshotCapture }, function(results)
for capture, result in pairs(results) do
if result then
print("Ảnh chụp đã được lưu")
end
end
end)
end
end
parent.Activated:Connect(function()
CaptureService:TakeScreenshotCaptureAsync(onCaptureReady, { UICaptureMode = Enum.UICaptureMode.All })
end)

UploadCaptureAsync
Sinh Lợi
Các khả năng: Capture
CaptureService:UploadCaptureAsync(capture:Capture):Tuple
Tham Số
capture:Capture
Lợi Nhuận
Mẫu mã
Tải lên bản chụp đến hệ thống tài sản
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
-- Xử lý lỗi
return nil
end
return assetId
end)
if not success then
-- Xử lý lỗi
return nil
end
return result
end

Sự Kiện
CaptureBegan
Các khả năng: Capture
CaptureService.CaptureBegan(captureType:Enum.CaptureType):RBXScriptSignal
Tham Số
captureType:Enum.CaptureType

CaptureEnded
Các khả năng: Capture
CaptureService.CaptureEnded(captureType:Enum.CaptureType):RBXScriptSignal
Tham Số
captureType:Enum.CaptureType

CaptureSaved
Đã Lỗi Thời

UserCaptureSaved
Các khả năng: Capture
CaptureService.UserCaptureSaved(captureContentId:ContentId):RBXScriptSignal
Tham Số
captureContentId:ContentId

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.