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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -