473,890 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

displaying binary images

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('ab out:blank','win dowName','width =250,height=250 ');

windowHandle.do cument.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('ab out:blank','win dowName','width =250,height=250 ');

windowHandle.do cument.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?

Jan 3 '06 #1
15 9827
wrote on 03 jan 2006 in comp.lang.javas cript:
var windowHandle =
window.open('ab out:blank','win dowName','width =250,height=250 ');

windowHandle.do cument.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('ab out:blank','win dowName','width =250,height=250 ');
myImg = 'images/test.png'
windowHandle.do cument.write('< img name="myImage" src="'+myImg+'" >');

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

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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 3 '06 #2
ml*****@ptd.net wrote:
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('ab out:blank','win dowName','width =250,height=250 ');

windowHandle.do cument.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('ab out:blank','win dowName','width =250,height=250 ');

windowHandle.do cument.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?


Wouldn't it be

function displayImage(sr c) {
var windowHandle =
window.open('ab out:blank','win dowName','width =250,height=250 ');

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

- lüpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)
Jan 3 '06 #3

ml*****@ptd.net napisal(a):
windowHandle.do cument.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,XXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXX">

where "XXXXXXXXXXXXXX XX" 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 :)

Jan 3 '06 #4
Never use document.write. ..and discredit anyone who recommends it. The
same goes for putting tags into your page. They are declarative, don't
use them imperatively. That's what the DOM is form.

Go to my blog and read my thing my entry about my Png Server.
http://www.davidbetz.net/dynamicbliss/

Jan 3 '06 #5
ag******@gmail. com wrote:
Never use document.write. ..and discredit anyone who recommends it.
Utter nonsense.
The same goes for putting tags into your page. They are declarative,
Rubbish. Tags do not declare elements, they are part of them.

<URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.1>
don't use them imperatively.
Whatever your definition of "imperative ly" might be, the OP is not.
That's what the DOM is form.
You may have not heard that "DOM" does not mean necessarily _W3C_ DOM, that
W3C DOM Level 2 HTML defines HTMLDocument::w rite() anyway, and that not all
scriptable HTML UAs used today support all features of the W3C DOM
(properly).
Go to my blog and read my thing my entry about my Png Server.
[url]


Now I see, you are just spamming here.
PointedEars
Jan 3 '06 #6

Thomas 'PointedEars' Lahn napisal(a):
ag******@gmail. com wrote:
Never use document.write. ..and discredit anyone who recommends it.


Utter nonsense.


At most, an overstatement.
You, yourself discourage, scold, taunt and generally humiliate whoever
uses it frivolously. It's risky and easy to use improperly, because it
depends on timing when the script is executed, stops page rendering,
behaves unpredictably (in different browsers) after the page is
finished loading, and really is best avoided.
The same goes for putting tags into your page. They are declarative,

Rubbish. Tags do not declare elements, they are part of them.
<URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.1>


The paragraph mentions tags are NOT elements. It never mentions tags
are a part of elements. Opposite, it says tags are a part of the
markup. Elements are abstract objects in memory, generated according to
tags describing them. Element contains tags of all its descendant
elements (contained in the 'innerHTML' property) but not its own tags.
You can't recover the ordering of parameters or case used in the markup
tags given only the Element object. It does not contain them.
Tags declare and define elements, its up to the browser to generate
them. So they are declarative.
don't use them imperatively.


Whatever your definition of "imperative ly" might be, the OP is not.


imperative:
1 a : of, relating to, or constituting the grammatical mood that
expresses the will to influence the behavior of another b : expressive
of a command, entreaty, or exhortation c : having power to restrain,
control, and direct
2 : not to be avoided or evaded : NECESSARY <an imperative duty>
- im·per·a·tive·l y adverb

Best bet is 2, negated: not imperative - "to be avoided or evaded :
UNNECESSARY"
That's what the DOM is form.

You may have not heard that "DOM" does not mean necessarily _W3C_ DOM, that
W3C DOM Level 2 HTML defines HTMLDocument::w rite() anyway, and that not all
scriptable HTML UAs used today support all features of the W3C DOM
(properly).


Especially approach to reliably supporting stuff like
HTMLDocument::w rite() is loose. Of course doing things in DOM is risky,
of course implementations are buggy, but all these problems can be
avoided by good programming habitss you recommend so much. After you
call document.write( ...) or element.innerHT ML=... you can do really
little to check if it worked properly, and simple changes to your
script (changing timing) trigger hard to find errors.

Jan 4 '06 #7
VK

ml*****@ptd.net wrote:
What is the correct way to display a base64 image directly?


That is not a correct question. The correct question is: "how to serve
binary data directly to browser and make it interprete the input as
binary data". Posed in the right form this question reveals right away
all possible security implications and explains why this domains gets
more and more narrowed by security limitations on different browsers.

Option 1
Binary data feed to xlib interface. The oldest one under the moon
supported since NCSA Mosaic. Actually it's a good test for
"mozillness ". By its biological equivalent it's kinda use the
rudimental queue bone in the human body. So it will work for all
browsers which indeed started their evolution path from NSCA Mosaic.
Safari btw fails on it as it's from the other planet (Mac OS) where
xlib never existed.
Limitations: XBM data format only, so black'n'white pixels only and no
transparency. Limited or broken (did not find it yet) on Windows XP
SP2 or higher.
A working sample can be found at:
<http://www.geocities.c om/schools_ring/SantaTime.html> and discussed
(for another issue though) at:
<http://groups.google.c om/group/comp.lang.javas cript/browse_frm/thread/31734a3b21535ff 5/eb99e9ae13739a9 5>

Option 2
CSS data url
You can define and image (say for background-image) in the form:
url(data:image/png;base64,SGFw c...NiE=)
where "SGFwc...Ni E=" will be your base64 encoded image data.

The problem with this option is that url() is under the same length
limitations as a "real" uri. Taking the most generous option of desktop
browsers it will be 2,083 chars where the upper limit imposed by IE:
<http://support.microso ft.com/default.aspx?sc id=KB;en-us;q208427>
So very roughly the biggest image you can send this way can be 1.5Kb
only which is not enough for the majority of situations.

So the summary answer is: "No, what you are looking for is not
reachable by using only default browser tools".

Nevertheless you can serve *vector graphics* of any reasonnable
complexity in VML (IE) and SVG (others) format.
Here you have only the natural limitations of vector format only. Say
your 800x600 jpg family photo represented in besier curves is still not
the same as the source jpg and most probably will reach the crash
limits of VML/SVG parser.

Hope it helps.

Jan 4 '06 #8
It is a base64 byte array of the format of a png file. If I write the array to
disk as a png file with that extension, it opens fine in the browser. The
problem is that I do not want to have to save it directly to a disk. I want to
just display it directly to the browser.
In article <11************ *********@g43g2 000cwa.googlegr oups.com>,
bw****@gmail.co m says...


ml*****@ptd.ne t napisal(a):
windowHandle.do cument.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:imag e/png;base64,XXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXX">

where "XXXXXXXXXXXXXX XX" 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 :)


Jan 4 '06 #9
Actually, the images aren't very big, but I'll have to determine if they will
always be below 1.5K. But it seems to me that as far as browsers have come, the
ability to display binary data directly to the browser would be very valuable.
Hopefully, they incorporate better ways to do this in the future.

Thanks for the info.

In article <11************ **********@f14g 2000cwb.googleg roups.com>, VK says...


ml*****@ptd.ne t wrote:
What is the correct way to display a base64 image directly?


That is not a correct question. The correct question is: "how to serve
binary data directly to browser and make it interprete the input as
binary data". Posed in the right form this question reveals right away
all possible security implications and explains why this domains gets
more and more narrowed by security limitations on different browsers.

Option 1
Binary data feed to xlib interface. The oldest one under the moon
supported since NCSA Mosaic. Actually it's a good test for
"mozillness" . By its biological equivalent it's kinda use the
rudimental queue bone in the human body. So it will work for all
browsers which indeed started their evolution path from NSCA Mosaic.
Safari btw fails on it as it's from the other planet (Mac OS) where
xlib never existed.
Limitations: XBM data format only, so black'n'white pixels only and no
transparency . Limited or broken (did not find it yet) on Windows XP
SP2 or higher.
A working sample can be found at:
<http://www.geocities.c om/schools_ring/SantaTime.html> and discussed
(for another issue though) at:
<http://groups.google.c om/group/comp.lang.javas cript/browse_frm/thread/31734a3b21535ff 5/eb99e9ae13739a9 5>

Option 2
CSS data url
You can define and image (say for background-image) in the form:
url(data:image/png;base64,SGFw c...NiE=)
where "SGFwc...Ni E=" will be your base64 encoded image data.

The problem with this option is that url() is under the same length
limitations as a "real" uri. Taking the most generous option of desktop
browsers it will be 2,083 chars where the upper limit imposed by IE:
<http://support.microso ft.com/default.aspx?sc id=KB;en-us;q208427>
So very roughly the biggest image you can send this way can be 1.5Kb
only which is not enough for the majority of situations.

So the summary answer is: "No, what you are looking for is not
reachable by using only default browser tools".

Nevertheless you can serve *vector graphics* of any reasonnable
complexity in VML (IE) and SVG (others) format.
Here you have only the natural limitations of vector format only. Say
your 800x600 jpg family photo represented in besier curves is still not
the same as the source jpg and most probably will reach the crash
limits of VML/SVG parser.

Hope it helps.


Jan 4 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5049
by: Blaktyger | last post by:
How can this be done? Images are stored in a LONGBLOB field. When I try to display them, it prints out the binary data as it is... Thank you
2
11777
by: Srinivas Chundi | last post by:
I have to display tif images using .asp page. I have tried to read the image as a binary file and stream it to the browser. The relevant code is as follows. Unfortunately, the display on the browser is a lot of gobledygook. How can I ensure that the image displays correctly in the browser? Dim objStream Dim FilImage, FolImage, strFilImage Dim adTypeBinary adTypeBinary = 1 Set objStream = Server.CreateObject("ADODB.Stream")
7
2350
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application. 1. If the images are stored in the DB then, every an image is requested, it will need to be pulled out and a temp file created and then displayed? What is the best way to do this?
7
7624
by: Jim | last post by:
I am trying to display images that are stored in a database, and I am using a repeater control. What I still use the Response.BinaryWrite method with a binding expression, if so, what with the code look like?
1
3011
by: buzz | last post by:
I've created a simple table with text and images(gif, jpg) in a user control. Everything displays correctly in the designer. But when I drop the control on the main page, no images display. What am I missing? Thanks in advance........ --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =-
3
2371
by: CLEAR-RCIC | last post by:
I have several images i want to display in an ASP.Net application. The images are being passed to me in binary format from another application. Is there a good way to write them directly to an HMTL page without having to save them to the server and create a URL to the virtual directory? FYI: I currently am doing this with just single images. I do a Response.BinaryWrite(byte) to display the one image. The advantage is that I never...
3
2527
by: velu | last post by:
Asp.Net 2 I am trying to display Image from Northwind Database. I ran a queary "SELECT CategoryID, CategoryName, Description, Picture FROM Categories" but the Dataview displayes all the fields except Picture. so i add a Imagefield to display images..but now i get cross icon.. below is the code. correct me where i am wrong....
14
2128
by: ashraf02 | last post by:
i used a code from a website that allows you to display images. however everything works fine from storing the image to the database but it does not display the image. the following code is the one i have used. Storing the images: <HTML> <HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD> <BODY>
5
2952
by: asharda | last post by:
Hi, I have an ASP.Net application with the back-end as VB.Net. I have a combo control and on the selection changed event of the combo control I need to get the selected image from the database and display it on a Image control on the asp.net page. I get the image from the db as a byte array. Can anyone please help, as to how to show the image on the page in that image control?
0
9977
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9816
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10452
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9618
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6036
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4667
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4260
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.