美文网首页
Flutter混编base64不匹配问题

Flutter混编base64不匹配问题

作者: KeyboardDirver | 来源:发表于2022-04-27 20:15 被阅读0次

    项目是混编项目
    iOS端将图片的NSData base64后传给flutter 。flutter负责显示图片。

    iOS端代码

    NSData * imgData = UIImageJPEGRepresentation(snapShotImage , 0.0);
    ///传的就是这个imgBase64Str
    NSString * imgBase64Str = [imgData base64EncodedString];
    

    flutter端代码

    String imgData = dataMap['imgData']; //发现iOS端的base64有换行(\r\n) 去掉(\r\n)
    String noNString = imgData.replaceAll('\r\n', '');
    //这个是可以展示的base64数据
      // String imgData =
      //     'iVBORw0KGgoAAAANSUhEUgAAAEYAAAAjCAIAAACmdes6AAACP0lEQVR4Xu2W0U3EQAxETxSA+OMnFdAL30AV1EUproB2SGJwhpldZ7MJEBDSfCT22Ot3vj3dxV5f/pguGvrt+kf6Mg2P9xrs01mQbKY6BOxESK79YKdDcu0BOwype4JEfT1PjWRd6zo7kmsTWCvSzfXzKAo+PdyFxiPxVW2X26ui0KlZ9DSC7UJyIZJmyaaDqnLPKlgTkvPUkGweN7akWTd4Kpk1lHgCJqFaR3KSHMnmM3Ikf0jGDSUeJKmt63gkpcJgMm4o8SiDgq0gBcYmJKSi12TcRo9SeTDiGVIweEGO5DZC0qWNg+rnSgokdPqzCgv9tYpEaxmfa41CHsddEY9VxtU+dBZFsFBTGRK9YqTW3T4jUU+TLxV1QE/xiCjRqqVcQyY8HtGgS89uQUJ5bTGoo+txfISGiqMnSCE8bKj8psfEtfLw1Ob+biSDFRXPTpCiyTBvTGvJU0yZIsXcVNaIhJvBS4V4OZLBr2Jt7iQ1leOLz03C7hHURvaBhBG9VKvjuie31eLv5fiiPAme9kqQIk5fvGIrvUtkS2aYyjVUlC4H8RymeAZRrd6l8OjcRFg8bip3hyZIioSi26LZQ5BctfhSHj7NoRKkGDeaIN7w+b/ffiTsr6mpPEyaQ21CIiFeICVUhERtMYjZeFjuUm0glyLhZ+/SDrofxUM/AqMNq9zpDxhf/NgxCvq0tZxGqWW10LMa9PhPIpEIrw/J9Ec8sbZoZ3mI8FS1uJ0Wyda25AYNmiIl1hbtqSV1I70B+dAU/4dAw64AAAAASUVORK5C';
    print('截屏base64:$noNString');
    Uint8List imageBytes = base64.decode(noNString);
    //展示
    Image.memory(
                        imageBytes!,
                        fit: BoxFit.contain,
                        gaplessPlayback: true, //防止重绘
                      );
    

    带有(\r\n)的base64前半部分截图

    /9j/4AAQSkZJRgABAQAA2ADYAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAAB
    
    AAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAAB
    
    AAAAWgAAAAAAAADYAAAAAQAAANgAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAA
    
    BGWgAwAEAAAAAQAAA7oAAAAA/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAA
    
    OEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/AABEIA7oEZQMBIgACEQEDEQH/
    
    xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUE
    
    BAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZ
    

    [参考链接](https://www.cnblogs.com/jieling/articles/13177401.html

    相关文章

      网友评论

          本文标题:Flutter混编base64不匹配问题

          本文链接:https://www.haomeiwen.com/subject/ndzdxrtx.html