显示二进制图像 [英] displaying binary images

查看:93
本文介绍了显示二进制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开第二个窗口并显示一个二进制图像,该图像是通过XMLRPC从一个java程序返回的。返回的数据是二进制编码的base64 png

文件。如果我将数据写入服务器上的文件,我可以使用

显示以下javascript


var windowHandle =

window.open(''about :blank'',''windowName'',''width = 250,height = 250'');


windowHandle.document.write(''< img name =" myImage" src =" images / test.png">'');

,图像显示正常。但是,如果我通过变量将二进制编码数据返回到我的

javascript函数,我将如何在另一个窗口中显示它?


我已经尝试了以下,并没有得到控制台错误,但图像没有显示:

var windowHandle =

window.open(''about :blank'',''windowName'',''width = 250,height = 250'');


windowHandle.document.write(''< img name =" myImage" src =" javascript :png">'');


其中png是包含base64二进制数组表示形式的变量

从服务器返回的png文件。


显示的正确方法是什么一个base64图像直接?

I want to open a second window and display a binary image that is returned from
a java program via XMLRPC. The data returned is a binary encoded base64 png
file. If I write the data out to a file on my server, I can display it using
the following javascript:

var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');

windowHandle.document.write(''<img name="myImage" src="images/test.png">'');

and the image displays fine. But if I return the binary encoded data to my
javascript function via a variable, how would I display it in the other window?

I''ve tried the following, and get no console errors, but the image doesn''t
display:

var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');

windowHandle.document.write(''<img name="myImage" src="javascript:png">'');

where png is the variable that contains a base64 binary array representation of
the png file that was returned from the server.

What is the correct way to display a base64 image directly?

推荐答案

于2006年1月3日在comp.lang.javascript中写道 :< br>
wrote on 03 jan 2006 in comp.lang.javascript:
var windowHandle =
window.open(''about :blank ',''windowName'',''width = 250,height = 250'');

windowHandle.document.write(''< img name =" myImage"
src =" images / test.png">'');

图像显示正常。但是如果我通过变量将二进制编码数据返回到我的javascript函数中,我将如何在另一个窗口中显示它?
var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');

windowHandle.document.write(''<img name="myImage"
src="images/test.png">'');

and the image displays fine. But if I return the binary encoded data
to my javascript function via a variable, how would I display it in
the other window?




var windowHandle =

window.open(''about :blank'',''windowName'',''width = 250,height = 250'');

myImg =''images / test.png''

windowHandle.document.write(''< img name =" myImage" src ="''+ myImg +''">'');


==============

或简单地说:

==============


myImg =''images / test.png''

window.open(myImg,'''',''width = 250,height = 250'');


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)



var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');
myImg = ''images/test.png''
windowHandle.document.write(''<img name="myImage" src="''+myImg+''">'');

==============
or simply:
==============

myImg = ''images/test.png''
window.open(myImg,'''',''width=250,height=250'');

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


ml ***** @ ptd.net 写道:
我想打开第二个窗口并显示一个箱子通过XMLRPC从java程序返回的ary图像。返回的数据是二进制编码的base64 png
文件。如果我将数据写入服务器上的文件,我可以使用以下javascript

var windowHandle =
窗口显示它。 open(''about :blank'',''windowName'',''width = 250,height = 250'');

windowHandle.document.write( ''< img name =" myImage" src =" images / test.png">'');

并且图片显示正常。但是如果我通过变量将二进制编码数据返回到我的
javascript函数,我将如何在另一个窗口中显示它?

我已经尝试了以下内容,并且没有得到控制台错误,但图像没有显示:

var windowHandle =
window.open(''about :blank'',' 'windowName'',''width = 250,height = 250'');

windowHandle.document.write(''< img name =" myImage" src =" javascript :png">'');

其中png是包含从服务器返回的png文件的base64二进制数组表示的变量。

直接显示base64图像的正确方法是什么?
I want to open a second window and display a binary image that is returned from
a java program via XMLRPC. The data returned is a binary encoded base64 png
file. If I write the data out to a file on my server, I can display it using
the following javascript:

var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');

windowHandle.document.write(''<img name="myImage" src="images/test.png">'');

and the image displays fine. But if I return the binary encoded data to my
javascript function via a variable, how would I display it in the other window?

I''ve tried the following, and get no console errors, but the image doesn''t
display:

var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');

windowHandle.document.write(''<img name="myImage" src="javascript:png">'');

where png is the variable that contains a base64 binary array representation of
the png file that was returned from the server.

What is the correct way to display a base64 image directly?




不是吗


函数displayImage(src){

var windowHandle =

window.open(''about :blank'',''windowName '',''宽度= 250,身高= 250'');


windowHa ndle.document.write(''< img name =" myImage" src ="''+ src +''">'');

}

-


- lüpher

------------------------ ---------------------

Man sieht nur das,man wei? (歌德)



Wouldn''t it be

function displayImage(src) {
var windowHandle =
window.open(''about:blank'',''windowName'',''width=250, height=250'');

windowHandle.document.write(''<img name="myImage" src="''+src+''">'');
}
--

- lüpher
---------------------------------------------
"Man sieht nur das, was man wei?" (Goethe)



ml ***** @ ptd。 net napisal(a):

ml*****@ptd.net napisal(a):
windowHandle.document.write(''< img name =" myImage" src =" javascript :png" >'');

其中png是包含base64二进制数组表示的变量


数组?好吧,你需要一个base64字符串。我不确定你的

数组的格式是什么,但是我打赌将它改成字符串不应该太难。


从服务器返回的png文件。

直接显示base64图像的正确方法是什么?
windowHandle.document.write(''<img name="myImage" src="javascript:png">'');

where png is the variable that contains a base64 binary array representation
Array? well, you need a base64 string. I''m not sure what format your
array is, but I bet changing it into a string shouldn''t be too hard.
of
the png file that was returned from the server.

What is the correct way to display a base64 image directly?




< img

src =" data:image / png; base64,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX">


其中XXXXXXXXXXXXXXXX"是base64编码的图像内容。

当然,如果数据:URL超过256

chars(以及大于几个像素的任何内容),它将在MSIE中失败,它会),所以更好

寻找它的替代解决方案(可能有一些ActiveX

控制可以做到 - 不是''正确''的方式,但工作的一个:)



<img
src="data:image/png;base64,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX">

where "XXXXXXXXXXXXXXXX" is the base64-encoded image content.
Of course it will fail in MSIE if the data: URL is longer than 256
chars (and for anything bigger than a few pixels, it will), so better
look for alternate solutions for it (probably there is some ActiveX
control that can do it - Not a ''correct'' way but a working one :)


这篇关于显示二进制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆