473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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('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?

Jan 3 '06 #1
15 9759
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">');

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+'">');

==============
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)
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('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?


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)
Jan 3 '06 #3

ml*****@ptd.net napisal(a):
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">

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 :)

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 "imperatively" 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::write() 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 "imperatively" 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·ly 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::write() 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::write() 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.innerHTML=... 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.com/schools_ring/SantaTime.html> and discussed
(for another issue though) at:
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/31734a3b21535ff5/eb99e9ae13739a95>

Option 2
CSS data url
You can define and image (say for background-image) in the form:
url(data:image/png;base64,SGFwc...NiE=)
where "SGFwc...NiE=" 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.microsoft.com/default.aspx?scid=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*********************@g43g2000cwa.googlegroups. com>,
bw****@gmail.com says...


ml*****@ptd.net napisal(a):
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">

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 :)


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**********************@f14g2000cwb.googlegroups .com>, VK says...


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.com/schools_ring/SantaTime.html> and discussed
(for another issue though) at:
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/31734a3b21535ff5/eb99e9ae13739a95>

Option 2
CSS data url
You can define and image (say for background-image) in the form:
url(data:image/png;base64,SGFwc...NiE=)
where "SGFwc...NiE=" 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.microsoft.com/default.aspx?scid=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

ml*****@ptd.net napisal(a):
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.


Well, all modern (by 'modern' i mean less than some 4-5 years old)
browsers properly implement the data: URL without imposing such
ridiculous size limits.
If you have more control over the images, you can display bigger images
as a mosaic composed of several smaller ones.

Jan 4 '06 #11
VK

bw****@gmail.com wrote:
Well, all modern (by 'modern' i mean less than some 4-5 years old)
browsers properly implement the data: URL without imposing such
ridiculous size limits.


It is not about image size limit: it is about URL length limit, and the
latter gets more and more shorter in Internet Explorer (because people
are using GET method more and more creatively). Unfortunately it is
diffucult to just say "screw on IE, I don't care" ;-)

Jan 4 '06 #12
Yeah, I understand the length of the url problem. I think I'm just going to end
up saving the image to a temp file and loading the image from that dynamically.

In article <11**********************@f14g2000cwb.googlegroups .com>, VK says...


bw****@gmail.com wrote:
Well, all modern (by 'modern' i mean less than some 4-5 years old)
browsers properly implement the data: URL without imposing such
ridiculous size limits.


It is not about image size limit: it is about URL length limit, and the
latter gets more and more shorter in Internet Explorer (because people
are using GET method more and more creatively). Unfortunately it is
diffucult to just say "screw on IE, I don't care" ;-)


Jan 4 '06 #13
Thanks. I checked out your page. Good info on png. But it doesn't help if I
cannot use IE. IE is a requirement. Looks like I'll have to go back to the ol'
fashion way of writing the image to a temp file and loading it dynamically.

Thanks again.

In article <11**********************@o13g2000cwo.googlegroups .com>,
ag******@gmail.com says...

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 4 '06 #14
VK

mlea...@ptd.net wrote:
Yeah, I understand the length of the url problem. I think I'm just going to end
up saving the image to a temp file and loading the image from that dynamically.


Wait a second... That was the discussion about binary data delivery for
postponed usage (via script). If you just want to display automatically
generated images on your page, then there are no problems whatsoever:

<img src="pngGenerator.php?image=foo"...

<img> doesn't care if the image is a real one or runtime generated: as
long as the content type header is right (say image/png) and the data
structure is matching to the declared type.

src attribute is still under the mentioned URI limitation but should be
no problem for the absolute majority of situations.

Jan 4 '06 #15
On 2006-01-04, VK <sc**********@yahoo.com> wrote:

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:


XBM is a text format (C source) so I can't really call that "binary data"
<http://www.geocities.com/schools_ring/SantaTime.html> and discussed
(for another issue though) at:
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/31734a3b21535ff5/eb99e9ae13739a95>


I was able to pass binary (.gif) images to mozilla. encoding one byte per
character.

Bye.
Jasen
Jan 5 '06 #16

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

Similar topics

5
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
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...
7
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....
7
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...
1
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...
3
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...
3
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...
14
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.