嵌入式 Base64 图像不会在 Dolphin 或 Android Stock 浏览器中显示

发布于 2024-12-03 14:00:10 字数 853 浏览 0 评论 0原文

我整个下午都在谷歌上搜索这个问题,似乎找不到任何 Dolphin 和 Base64 图像或数据 URL 一起出现的搜索。但是,当我找到有关一般嵌入 Base64 图像的文章时,他们几乎都说它适用于除 IE 之外的几乎所有浏览器。当然,我不能只查看该死的页面源代码或设备(Samsung Galaxy Tab Gingerbread)上的任何错误控制台来查看页面正在解释的内容。我得到的只是?图像应该在哪里。适用于 Chrome 和 Opera,但 Dolphin 或普通浏览器都不起作用。

基本上,我有一个第三方签名板控件,其签名图像作为 base64 编码字符串返回给我。然后,我采用该 base64 编码字符串,将其转换为 DataURL 并将其作为 src 分配给我的 img 控件。在 Chrome 和 Opera 上运行起来就像一个魅力,但在我需要它运行的任何移动浏览器上都不起作用。

 var canvas = signaturestr.toDataURL("image/png") //Have also tried jpg and bmp
 $("#image").attr("src", canvas)

这给了我?图像应该在哪里。因此,要么我需要一种方法来获取数据 url 并使其被这些浏览器接受,要么我需要能够使用原始 base64 代码来生成图像。同样重要的是要注意,这是一个离线应用程序,我需要所有解决方案都采用 javascript 或 jquery。

编辑:发现来自其他网站的 Base64 图像(包括来自 stackoverflow 论坛的头像)确实出现在这些浏览器上。已尝试缩小图像的大小,但仍然没有成功。仍然得到替代文本和?。尺寸绝对不是问题。将我的图像缩小到比有效头像更小的尺寸。真的不知道为什么这个图像不能在这些浏览器上工作。看起来与有效的图像完全相同。

I have been googling this problem all afternoon and can't seem to find any search anywhere where the words Dolphin and Base64 Image or Data URL appear together. But when I find articles about just embedding base64 images in general, they pretty much all say it works on almost every browser but IE. Of course I can't just view the darn page source or any error consoles on the device either (Samsung Galaxy Tab Gingerbread) to see what the page is interpreting. All I get are ? where the image should be. Works on Chrome and Opera, but neither Dolphin or the stock browser work.

Basically, I have a third party signature pad control whose signature image is returned to me as a base64 encoded string. I am then taking that base64 encoded string, converting it toDataURL and assigning it as the src to my img control. Works like a charm on Chrome and Opera, but not on either of the mobile browsers I need it to work on.

 var canvas = signaturestr.toDataURL("image/png") //Have also tried jpg and bmp
 $("#image").attr("src", canvas)

This gives me ? where the images should be. So either I need a way to take a data url and make it acceptable to these browsers, or I need to be able to use the raw base64 code to generate an image. Also important to note, this is an offline application and I need all solutions to be in javascript or jquery.

Edit: Found that base64 images from other websites (including avatars from stackoverflow forums) do appear on these browsers. Have tried reducing the size of my image, and still no luck. Still get the alt text and ?. Size is definitely not the issue. Reduced my image to a smaller size than that of the avatar that works. Genuinely at a loss as to why this image doesn't work on these browsers. Seems like the exact same thing as the images that work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

四叶草在未来唯美盛开 2024-12-10 14:00:10

我遇到了类似的问题,并发现:

当您尝试加载 JPEG 文件时,dataURL 是错误的......它以 data:base64 开头code> 而不是 data:image/jpeg;base64。我解决了这个问题:

var image = new Image();
image.onload = doSomethingElse();
image.src = myDataURL.replace('data:base64', 'data:image/jpeg;base64');

PNG 文件似乎工作正常。

我使用 Android 4(冰淇淋三明治)进行了测试,效果非常好 - 甚至可以直接从设备加载大照片。

I had a similar problem and found this:

When you attempt to load a JPEG file, the dataURL is wrong... it starts with data:base64 instead of data:image/jpeg;base64. I got around the problem with:

var image = new Image();
image.onload = doSomethingElse();
image.src = myDataURL.replace('data:base64', 'data:image/jpeg;base64');

PNG files seem to work ok though.

I tested using Android 4 (Ice Cream Sandwich) and it works great - even loads large photos straight from the device.

梦初启 2024-12-10 14:00:10

能够简单地在禁用控件的新实例上重新显示捕获的签名,而不是转换为图像并以这种方式显示。工作原理是一样的。

Was able to simply redisplay captured signature on new instance of disabled control rather than converting to an image and displaying that way. Works just the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文