You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2005/11/30 16:52:12 UTC
Error importing Images into an image tag?
When I try to link in an Image, I add the x, y, width, height, and
xlink:href attribute. When I place the Element on the JSVGCanvas, I get
an error telling me that xlink:href is required. I do have it as I can
verify by viewing the source of my document:
<image xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="red_06.jpg"
id="59FAB452-F82B-9202-6A5C-226937440F88"
transform="translate(0, 0) scale(1, 1)" width="130"
xlink:show="embed" xlink:type="simple"
preserveAspectRatio="xMidYMid meet" height="100" x="21"
y="312"
xlink:actuate="onLoad"/>
The odd thing is, I did NOT add the "xmlns:xlink" attribute, the
"xlink:show", "xlink:type", or "xlink:actuate" attributes. The
xlink:href is clearly there so maybe I'm doing something wrong. Here's
the code snippet:
element = SVGDocumentManager.createElement(SVGConstants.SVG_IMAGE_TAG);
String xCoordinate = String.valueOf(Status.getXCurrent());
String yCoordinate = String.valueOf(Status.getYCurrent());
String width = String.valueOf(ImageStatus.getWidth());
String height = String.valueOf(ImageStatus.getHeight());
String imageName = ImageStatus.getImageFile().getName();
element.setAttribute(SVGConstants.SVG_X_ATTRIBUTE, xCoordinate);
element.setAttribute(SVGConstants.SVG_Y_ATTRIBUTE, yCoordinate);
element.setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, width);
element.setAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE, height);
element.setAttribute("xlink:href", imageName);
Michael Bishop
Re: Error importing Images into an image tag?
Posted by th...@kodak.com.
Hi HardCoder,
hardc0d3r <ha...@gmail.com> wrote on 05/11/2007 12:06:32 PM:
> from what i understand, if my image is in the same folder as my program,
i
> only need to specify the filename.
I don't know why you would think that. Your images need to
be in the same folder as the document you are adding the image
elements to. If your document is created entirely on the fly
then it probably doesn't have a 'base URL'. You can associate
one by calling batik.dom.svg.SVGOMDocument.setURLObject(URL).
but i get a null pointer exception.. i am
> sure that the image and the program is on the same folder.. here is the
> code:
>
> private void loadImage() {
> try {
> SVGDocument doc = svgCanvas.getSVGDocument();
>
> Element mapLayer = doc.createElementNS(svgNS, "image");
> imageLayer.setAttributeNS(null, "x", "0");
> imageLayer.setAttributeNS(null, "y", "0");
> imageLayer.setAttributeNS(null, "width", "260");
> imageLayer.setAttributeNS(null, "height", "368");
> imageLayer.setAttributeNS(XLINK_NAMESPACE_URI, "xlink:href",
> "test.jpg");
>
> svgRoot.appendChild(imageLayer);
>
> } catch(Exception e) {
> System.out.println(e.toString());
> }
> }
>
> are ther any errors on the code?
> --
> View this message in context: http://www.nabble.com/Error-importing-
> Images-into-an-image-tag--tf646195.html#a10434915
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Error importing Images into an image tag?
Posted by hardc0d3r <ha...@gmail.com>.
from what i understand, if my image is in the same folder as my program, i
only need to specify the filename. but i get a null pointer exception.. i am
sure that the image and the program is on the same folder.. here is the
code:
private void loadImage() {
try {
SVGDocument doc = svgCanvas.getSVGDocument();
Element mapLayer = doc.createElementNS(svgNS, "image");
imageLayer.setAttributeNS(null, "x", "0");
imageLayer.setAttributeNS(null, "y", "0");
imageLayer.setAttributeNS(null, "width", "260");
imageLayer.setAttributeNS(null, "height", "368");
imageLayer.setAttributeNS(XLINK_NAMESPACE_URI, "xlink:href",
"test.jpg");
svgRoot.appendChild(imageLayer);
} catch(Exception e) {
System.out.println(e.toString());
}
}
are ther any errors on the code?
--
View this message in context: http://www.nabble.com/Error-importing-Images-into-an-image-tag--tf646195.html#a10434915
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Error importing Images into an image tag?
Posted by Archie Cobbs <ar...@dellroad.org>.
Bishop, Michael W. CONTR J9C880 wrote:
> When I try to link in an Image, I add the x, y, width, height, and
> xlink:href attribute. When I place the Element on the JSVGCanvas, I get
> an error telling me that xlink:href is required. I do have it as I can
> verify by viewing the source of my document:
>
> element.setAttribute("xlink:href", imageName);
You need to use setAttributeNS() instead.
-Archie
__________________________________________________________________________
Archie Cobbs * CTO, Awarix * http://www.awarix.com
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org