Engine Class
CaptureService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
วิธีการ
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: Dictionary):() |
UploadCaptureAsync(capture: Capture):Tuple |
เหตุการณ์
CaptureBegan(captureType: Enum.CaptureType):RBXScriptSignal |
CaptureEnded(captureType: Enum.CaptureType):RBXScriptSignal |
CaptureSaved(captureInfo: Dictionary):RBXScriptSignal |
UserCaptureSaved(captureContentId: ContentId):RBXScriptSignal |
เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
CaptureScreenshot
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
จับภาพหน้าจอ
local CaptureService = game:GetService("CaptureService")
-- อ้างอิงถึง ImageLabel ที่เป็นพ่อของสคริปต์ที่มีโค้ดนี้
local imageLabel = script.Parent
local function onCaptureReady(contentId)
imageLabel.Image = contentId
end
CaptureService:CaptureScreenshot(onCaptureReady)CheckUploadCaptureStatusAsync
PromptCaptureGalleryPermissionAsync
CaptureService:PromptCaptureGalleryPermissionAsync(captureGalleryPermission:Enum.CaptureGalleryPermission):boolean
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
ขออนุญาตเข้าถึงแกลเลอรีการจับภาพ
local CaptureService = game:GetService("CaptureService")
local function isGalleryAccessGranted()
local accepted = CaptureService:PromptCaptureGalleryPermissionAsync(Enum.CaptureGalleryPermission.ReadAndUpload)
return accepted
endPromptSaveCapturesToGallery
ส่งค่ากลับ
()
ตัวอย่างโค้ด
การแชร์การจับภาพ
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
ส่งค่ากลับ
ตัวอย่างโค้ด
อ่านการจับภาพจากแกลเลอรีและวนซ้ำผ่านหน้า
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
endStartUploadCaptureAsync
StartVideoCaptureAsync
CaptureService:StartVideoCaptureAsync(
พารามิเตอร์
| ค่าเริ่มต้น: "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
CaptureService:StopVideoCapture():()
ส่งค่ากลับ
()
TakeScreenshotCaptureAsync
พารามิเตอร์
| ค่าเริ่มต้น: "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
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
อัปโหลดการจับภาพไปยังระบบสินทรัพย์
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
พารามิเตอร์
CaptureEnded
พารามิเตอร์
CaptureSaved
UserCaptureSaved
พารามิเตอร์
captureContentId:ContentId |