I am not entirely sure what you want to achieve, but you can access the file content of a Mendix FileDocument (mendixFileDocument) by getting the inputstream like below:
InputStream inputStrm = Core.getFileDocumentContent(this.getContext(),this.mendixFileDocument.getMendixObject());
Can't you use the base64encodeFile from the CommunityCommons with your image document as inputparameter?