944,048 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1986
  • Java RSS
Jul 19th, 2005
0

Pictures

Expand Post »
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

Java Syntax (Toggle Plain Text)
  1. FileChooser3.setDialogType(JFileChooser.OPEN_DIALOG);
  2. FileChooser3.setDialogTitle("Select a picture to insert into document");
  3.  
  4. if(FileChooser3.showDialog(fr,"Insert") != JFileChooser.APPROVE_OPTION)
  5. {
  6. return;
  7. }
  8.  
  9. File g = FileChooser3.getSelectedFile();
  10. ImageIcon image1 = new ImageIcon(g.toString());
  11.  
  12. MutableAttributeSet mas1 = new SimpleAttributeSet();
  13. //The below command line gets the width and height of the image
  14.  
  15. int w = image1.getIconWidth();
  16. int h = image1.getIconHeight();
  17.  
  18. try
  19. {
  20. //The below six command line insertss the currently read in image into
  21. //the JTextPane
  22.  
  23. mas1.addAttribute(StyleConstants.NameAttribute, HTML.Tag.IMG);
  24. //The below command line is where the reliance occurs
  25.  
  26. mas1.addAttribute(HTML.Attribute.SRC, g.toURL().toString());
  27. mas1.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(h));
  28. mas1.addAttribute(HTML.Attribute.WIDTH, Integer.toString(w));
  29. int p = TextPane1.getCaretPosition();
  30. htmldoc.insertString(p, " ", mas1);
  31. }
  32.  
  33. catch(Exception e)
  34. {
  35. e.printStackTrace();
  36. }

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)
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <p>
  6. <img height="400" width="400" src="file:/D:/Sample_Pics/venu.jpg">
  7. </p>
  8. </body>
  9. </html>

See the reliance on the picture picture always being on that location on the disk on this line
Java Syntax (Toggle Plain Text)
  1. 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
Similar Threads
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 22nd, 2005
0

Re: Pictures

Come on...this should be an easy one...
HTML = (Hyper Text Markup Language)
So to answer your question, your going to find out that you cannot imbed a picture into a plain html document without using some kind class file instead of straight HTML code.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Sauce is offline Offline
55 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: textFields help
Next Thread in Java Forum Timeline: Writing a loop statement that produces desired output





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC