RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1524 | Replies: 1
Reply
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Help Pictures

  #1  
Jul 19th, 2005
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

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
<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
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Posts: 56
Reputation: Sauce is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Sauce Sauce is offline Offline
Junior Poster in Training

Re: Pictures

  #2  
Jul 22nd, 2005
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:37 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC