| | |
Pictures
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
I am trying to add pictures into a html document and so far everthing has been going well but i have a question. Wen i insert the pictures into the html document they show up and i am able to save them to disk in html format.
The thing is when i delete the picture on the disk and read the html document the picture does not show up but if the picture is not deleted from the disk then when i read the html document the picture shows up.
Basically what i need to know if there is a way in which i can embed a picture into the html document without any reliance on the picture that is saved on a different location on the disk.
For example if the Styled Document is serialized with an embedded picture even if the picture is deleted from the disk when the Styled Document is read the picture is not there but this is not so for the HTML Document class.
Basically my question is that is it possible to implement something like that in which that the picture is embedded in the HTML Document and it does not matter if the picture is deleted or not from the disk thus even when the html document is read the embedded picture is still there.
This is what i am doing to insert the picture into the HTML Document
Note that the file name of the picture is converted to a URL and the Html Tag there always depend on the file name with the picture being there
please note that htmldoc is an instance of the Java HTMLDocument class and TextPane1 is an instance of the Java JTextPane class
This is its HTMl equivalent that is generated in the html document
See the reliance on the picture picture always being on that location on the disk on this line
Is there a way to achieve what i need by simple ways or style sheets or any other way??
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
I am trying to add pictures into a html document and so far everthing has been going well but i have a question. Wen i insert the pictures into the html document they show up and i am able to save them to disk in html format.
The thing is when i delete the picture on the disk and read the html document the picture does not show up but if the picture is not deleted from the disk then when i read the html document the picture shows up.
Basically what i need to know if there is a way in which i can embed a picture into the html document without any reliance on the picture that is saved on a different location on the disk.
For example if the Styled Document is serialized with an embedded picture even if the picture is deleted from the disk when the Styled Document is read the picture is not there but this is not so for the HTML Document class.
Basically my question is that is it possible to implement something like that in which that the picture is embedded in the HTML Document and it does not matter if the picture is deleted or not from the disk thus even when the html document is read the embedded picture is still there.
This is what i am doing to insert the picture into the HTML Document
Note that the file name of the picture is converted to a URL and the Html Tag there always depend on the file name with the picture being there
Java Syntax (Toggle Plain Text)
FileChooser3.setDialogType(JFileChooser.OPEN_DIALOG); FileChooser3.setDialogTitle("Select a picture to insert into document"); if(FileChooser3.showDialog(fr,"Insert") != JFileChooser.APPROVE_OPTION) { return; } File g = FileChooser3.getSelectedFile(); ImageIcon image1 = new ImageIcon(g.toString()); MutableAttributeSet mas1 = new SimpleAttributeSet(); //The below command line gets the width and height of the image int w = image1.getIconWidth(); int h = image1.getIconHeight(); try { //The below six command line insertss the currently read in image into //the JTextPane mas1.addAttribute(StyleConstants.NameAttribute, HTML.Tag.IMG); //The below command line is where the reliance occurs mas1.addAttribute(HTML.Attribute.SRC, g.toURL().toString()); mas1.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(h)); mas1.addAttribute(HTML.Attribute.WIDTH, Integer.toString(w)); int p = TextPane1.getCaretPosition(); htmldoc.insertString(p, " ", mas1); } catch(Exception e) { e.printStackTrace(); }
please note that htmldoc is an instance of the Java HTMLDocument class and TextPane1 is an instance of the Java JTextPane class
This is its HTMl equivalent that is generated in the html document
Java Syntax (Toggle Plain Text)
<html> <head> </head> <body> <p> <img height="400" width="400" src="file:/D:/Sample_Pics/venu.jpg"> </p> </body> </html>
See the reliance on the picture picture always being on that location on the disk on this line
Java Syntax (Toggle Plain Text)
src="file:/D:/Sample_Pics/venu.jpg"
Is there a way to achieve what i need by simple ways or style sheets or any other way??
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
Similar Threads
- animated pictures and .GIF files (Graphics and Multimedia)
- Missing pictures in IE (Web Browsers)
- Frames of Pictures (C++)
- Printing pictures (Windows NT / 2000 / XP)
- Internet explorer: Where have all the pretty pictures gone? (Web Browsers)
- T720 Pictures (Geeks' Lounge)
Other Threads in the Java Forum
- Previous Thread: textFields help
- Next Thread: Writing a loop statement that produces desired output
Views: 1836 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
6 android api apple applet application arguments array arrays automation binary bluetooth bold byte c++ chat class classes client code component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle pong print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user web websites windows





