import image from '@ohos.multimedia.image';
import buffer from '@ohos.buffer';

export class PixelMapUtils {
  static  async pixelMapToBase64(pixelMap: image.PixelMap): Promise<string> {
    // 1. 创建图像打包器
    const imagePacker = image.createImagePacker();

    // 2. 设置打包选项 (PNG格式)
    const packOpts: image.PackingOption = {
      format: "image/png",
      quality: 100 // 最高质量
    };

    // 3. 打包到内存缓冲区
    const arrayBuffer = await imagePacker.packing(pixelMap, packOpts);

    // 4. 转换为Base64
    const base64Data = buffer.from(arrayBuffer).toString('base64');

    // 5. 添加Data URL前缀
    return base64Data;
  }


}