Set table size to image size.
Oxygen general issues.
-
- Posts: 58
- Joined: Sat Aug 01, 2009 12:57 am
Set table size to image size.
I am currently modifying DocBook InsertTable operation. One of the common tables to insert is a table that has mediaobject with imagedata as the body instead of the tgroup. I want to set the table width to the width of the image. I am having trouble getting the image width in Java. Currently I have:
TableInfo.java constructor
Is there a utility class in Author API that I can use for finding out the image size?
TableInfo.java constructor
Code: Select all
Image image = Toolkit.getDefaultToolkit().getImage(img_filename);
MediaTracker mTracker = new MediaTracker(the_table_dialog_object);
mTracker.addImage(image, 1);
try
{
mTracker.waitForID(1);
}
catch(InterruptedException e){}
image.getWidth(null); // returns -1
image.getHeight(null); // returns -1
-
- Posts: 9446
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Set table size to image size.
Hi Mike,
I can give you the code which is used on our side to detect widths and heights for images which are supported by Java:
Regards,
Radu
I can give you the code which is used on our side to detect widths and heights for images which are supported by Java:
Code: Select all
/**
* Get an image reader for the specified extension.
* @param is The input stream
* @return The image reader
*
* @throws IOException
*/
public static ImageReader getImageReader(InputStream is) throws IOException {
ImageReader imagereader = null;
try {
ImageInputStream imageStream = ImageIO.createImageInputStream(is);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(imageStream);
if (iterator.hasNext()) {
imagereader = iterator.next();
imagereader.setInput(imageStream);
}
} catch(IOException ex) {
ex.printStackTrace();
throw ex;
}
return imagereader;
}
public static void main(String[] args) throws IOException {
URL imageURL = ........;
boolean oldUseCache = ImageIO.getUseCache();
try {
ImageIO.setUseCache(false);
InputStream imageStream = imageURL.openStream();
ImageReader reader = null;
try {
reader = getImageReader(imageStream);
if (reader != null) {
int width = reader.getWidth(0);
int height = reader.getHeight(0);
}
} finally {
if(reader != null) {
reader.dispose();
}
imageStream.close();
}
}finally {
ImageIO.setUseCache(oldUseCache);
}
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 58
- Joined: Sat Aug 01, 2009 12:57 am
Re: Set table size to image size.
Thank you. It works now. I am using SimpleImageInfo class I found on the web http://jaimonmathew.wordpress.com/2011/ ... imageinfo/. It supposed to be faster than ImageIO. To get the file object of the image I am using AuthorUtilAccess.locateFile()
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service