imageElement.setXlinkHrefAttribute(AnyURI.decodePath(uri.toString()));
// Set mandatory attribute xlink:type
imageElement.setXlinkTypeAttribute("simple");
// A draw:image is always embedded in a draw:frame
InputStream is = mOdfSchemaDoc.getPackage().getInputStream(packagePath);
DrawFrameElement odfFrame = (DrawFrameElement) imageElement.getParentNode();
Frame aFrame = Frame.getInstanceof(odfFrame);
FrameRectangle oldRect = aFrame.getRectangle();
if (oldRect.getLinearMeasure() != StyleTypeDefinitions.SupportedLinearMeasure.CM)
oldRect.setLinearMeasure(StyleTypeDefinitions.SupportedLinearMeasure.CM);
if (odfFrame != null) {
BufferedImage image = ImageIO.read(is);
int height = image.getHeight(null);
int width = image.getWidth(null);
odfFrame.setSvgHeightAttribute(Length.mapToUnit(String.valueOf(height) + "px", Unit.CENTIMETER));
odfFrame.setSvgWidthAttribute(Length.mapToUnit(String.valueOf(width) + "px", Unit.CENTIMETER));
if (isResetSize) {
FrameRectangle newRect = aFrame.getRectangle();
newRect.setX(oldRect.getX()+(oldRect.getWidth()-newRect.getWidth())/2);
newRect.setY(oldRect.getY()+(oldRect.getHeight()-newRect.getHeight())/2);
aFrame.setRectangle(newRect);