Image Size Not Applied when opening OpenXML Word Document Created in C# -


i creating openxml word document inside c# web application , writing google chart image it. i'm specifying dimensions of image, seems, correctly. however, when open word document, image right height, not right width. in fact, square.

when click on image inside of word , go size , position, correct dimensions displayed. in case, 2.08" 5.04". when click "ok" after changing nothing, image stretches right size.

if try identify size appears as, close half defined width, may coincidence.

the native size of image 3.13" (h) 7.55" (w), doesn't seem should matter.

i followed following posts pretty closely:

i'm guessing i'm missing setting of sort, don't know one. paragraph or run need sized entire width of page? width of document need specified?

    public void addimage(string imagename, byte[] imagedata)     {         var img = system.drawing.image.fromstream(new memorystream(imagedata));          maindocumentpart mainpart = doc.maindocumentpart;          imagepart imagepart = mainpart.addimagepart(imageparttype.png);         memorystream imagestream = new memorystream(imagedata);         imagepart.feeddata(imagestream);          addimagetobody(mainpart.getidofpart(imagepart), img);     }      private void addimagetobody(string relationshipid, system.drawing.image img)     {         var widthpx = img.width;         var heightpx = img.height;         var horzrezdpi = img.horizontalresolution;         var vertrezdpi = img.verticalresolution;         const int emusperinch = 914400;         var widthemus = (long)(widthpx / horzrezdpi * emusperinch);         var heightemus = (long)(heightpx / vertrezdpi * emusperinch);         var maxwidthemus = (long)(6.5 * emusperinch);         if (widthemus > maxwidthemus)         {             var ratio = (heightemus * 1.0m) / widthemus;             widthemus = maxwidthemus;             heightemus = (long)(widthemus * ratio);         }          // define reference of image.         var element =              new drawing(                  new dw.inline(                      new dw.extent() { cx = widthemus, cy = heightemus }, // cx = 990000l, cy = 792000l },                                               new dw.effectextent()                      {                          leftedge = 0l,                          topedge = 0l,                          rightedge = 0l,                          bottomedge = 0l                      },                      new dw.docproperties()                      {                          id = (uint32value)1u,                          name = "picture 1"                      },                      new dw.nonvisualgraphicframedrawingproperties(                          new a.graphicframelocks() { nochangeaspect = true }),                      new a.graphic(                          new a.graphicdata(                              new pic.picture(                                  new pic.nonvisualpictureproperties(                                      new pic.nonvisualdrawingproperties()                                      {                                          id = (uint32value)0u,                                          name = "new bitmap image.jpg"                                      },                                      new pic.nonvisualpicturedrawingproperties()),                                  new pic.blipfill(                                      new a.blip(                                          new a.blipextensionlist(                                              new a.blipextension()                                              {                                                  uri =                                                    "{28a0092b-c50c-407e-a947-70e740481c1c}"                                              })                                      )                                      {                                          embed = relationshipid,                                          compressionstate =                                          a.blipcompressionvalues.print                                      },                                      new a.stretch(                                          new a.fillrectangle())),                                  new pic.shapeproperties(                                      new a.transform2d(                                          new a.offset() { x = 0l, y = 0l },                                          new a.extents() { cx = 990000l, cy = 792000l }),                                      new a.presetgeometry(                                          new a.adjustvaluelist()                                      ) { preset = a.shapetypevalues.rectangle }))                          ) { uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })                  )                  {                      distancefromtop = (uint32value)0u,                      distancefrombottom = (uint32value)0u,                      distancefromleft = (uint32value)0u,                      distancefromright = (uint32value)0u,                      editid = "50d07946"                  });          // append reference body, element should in run.         var p = new paragraph();          doc.maindocumentpart.document.body.appendchild(new paragraph(new run(element)));     } 

according code, have set cx , cy values both extent properties.

new dw.extent() { cx = widthemus, cy = heightemus } 

first 1 inline , second transform2d.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -