Firefox and Chrome won't decode base64 image or pdf files

前端 未结 3 1591
囚心锁ツ
囚心锁ツ 2021-02-11 03:29

I\'m trying to decode a base64 encoded images on the browser by using the data uri scheme.

This is what my html looks like:



        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-11 03:56

    I know this is a really old question but I have recently ran into the same issue. (Stemming from USPS label returns) I fixed it by converting the Base64 string encoded TIFF to a Base64 string Bitmap image (though you could use any image type that you wish).

    I was using C# to convert the images:

        Byte[] arrTiff = Convert.FromBase64String(FixBase64ForImage(oeVS.LabelImage));
        System.IO.MemoryStream msTiff = new System.IO.MemoryStream(arrTiff);
        Bitmap bmpTiff = new Bitmap((Bitmap)Image.FromStream(msTiff));
        System.IO.MemoryStream msBmp = new System.IO.MemoryStream();
        bmpTiff.Save(msBmp, System.Drawing.Imaging.ImageFormat.Bmp);
        Byte[] arrBmp = msBmp.ToArray();
        string sBMP64 = Convert.ToBase64String(arrBmp);
    

    Then in the html/javascript you can use this to display the label where sBMP64 is the result from above.

    BMP worked for my purposes, but here's a table of image support by browser: https://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support

提交回复
热议问题