Chuyển tới nội dung chính

saveImageToGallery

import { saveImageToGallery } from "zmp-sdk";

Lưu ảnh vào thư viện media của thiết bị.

Ví dụ

Thông báo một lần sau khi lưu ảnh xong:

await saveImageToGallery({
imageUrl: "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg",
});
console.log("Lưu ảnh thành công!");

Xử lý lỗi khi lưu ảnh:

try {
await saveImageToGallery({
imageUrl: "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg",
});
} catch (error) {
console.error(error);
}

Báo cáo tiến độ lưu ảnh:

await saveImageToGallery({
imageUrl: "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg",
onProgress: (progress) => {
console.log(`Đã lưu được ${progress}%...`);
},
});
console.log("Lưu ảnh thành công!");

Xem hướng dẫn xử lý lỗi và bảng mô tả chi tiết mã lỗi tại đây.

Tham số

Truyền tham số vào API dưới dạng object chứa các thuộc tính:

PropertyTypeRequiredDescription
imageBase64DatastringNoGiá trị base64 của ảnh cần lưu.
imageUrlstringNoĐường dẫn của ảnh cần lưu.
onProgress(progress: number) => voidNoCallback function tiến độ tải file. Với progress là số từ 0 đến 100%.