【问题标题】:How to send a canvas element in binary to a server in dart如何以二进制形式将画布元素发送到 dart 中的服务器
【发布时间】:2013-11-19 07:36:02
【问题描述】:

如何使用 Dart 将画布元素发送到服务器,而不会产生 base64 加密的开销?

【问题讨论】:

    标签: canvas base64 dart


    【解决方案1】:

    此代码将画布元素转换为 dart 中的二进制格式:

    import 'dart:html';
    import 'dart:core';
    import 'dart:typed_data';
    
    /*** possible values for imagetype: 'image/jpeg', 'image/png', 'image/webp' 
     *** see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement
     ***/
    Uint8List toUploadData(CanvasElement canvas, String imagetype, num quality) =>
      new Uint8List.fromList(window.atob(canvas.toDataUrl(imagetype,
          quality).split(",")[1]).codeUnits);
    

    然后可以按如下方式上传:

    UploadImageData(Uint8List imagedata) =>
        HttpRequest.request('myserverscript.php',
            method:"POST",
            sendData: imagedata);
    

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2018-09-25
      • 1970-01-01
      • 2015-05-03
      相关资源
      最近更新 更多