c# - Extract image from Docx -
i'm tryng export images docx file. how can convert encodedpackage shape object image?
sample of code:
documentformat.openxml.vml.shape shape = imageelement.descendants<documentformat.openxml.vml.shape>().firstordefault(); byte[] bytes = system.convert.frombase64string(shape.encodedpackage.value.replace("\n", "")); system.drawing.image image; using (memorystream ms = new memorystream(bytes)) { image = system.drawing.image.fromstream(ms); } image.save(filename);
you can image imagepart
. try this:
var imageparts = doc.maindocumentpart.imageparts; foreach (var imagepart in imageparts) { var uri = imagepart.uri; var filename = uri.tostring().split('/').last(); var stream = doc.package.getpart(uri).getstream(); bitmap b = new bitmap(stream); b.save(@"c:\extracted_images\" + filename); }
Comments
Post a Comment