If you have an existing image of identical type (eg jpg) in the document already which you want to replace, you can find its Part, and replace the binary content in the part using any of the methods:
- Code: Select all
public void setBinaryData(InputStream binaryData);
public void setBinaryData(byte[] bytes);
public void setBinaryData(ByteBuffer bb);
The main document part specifies dimensions etc though, so unless these are the same, you'll need to adjust there.
You may find it easier to just start from scratch (ie delete the image rel from the rels part, and remove the XML in the main document part which references it, then add your new image as per the AddImage sample). If there was a ReplaceImage method, that is what it would do (though it would check for edge case where the rel was referenced a second time from somewhere else)
To delete the image rel from the rels part, use RelationshipsPart methods:
- Code: Select all
public void removePart(PartName partName)
or public void removeRelationship(Relationship rel)