zoukankan      html  css  js  c++  java
  • C# word 图片大小

    通过Office自带的类库word文档中插入图片,图片大小的单位为磅

    而文档中,图片的大小已经固定,为CM。

    实际工作中,首先将图片插入到word中,根据目前的大小,计算转换为目标大小的比率,将长宽按照目标大小进行缩放即可。

    msword.InlineShape spa = oOperateDoc.Tables[oOperateDoc.Tables.Count].Cell(1, 1).Range.InlineShapes.AddPicture(jietuA);
    float yuanwidth = spa.Width;
    float yuanheidht = spa.Height;
    double bilv = GetChangepicSizeRation(yuanwidth,yuanheidht, targetW, targetH);
    spa.Width = (float)(yuanwidth * bilv);
    spa.Height = (float)(yuanheidht * bilv);
    

      

    private double GetChangepicSizeRation(double width_pt, double height_pt, double targetWidthCM, double targetHeightCM)
            {
                //CM转pt
                double p = 0.03527;// 0.03759;  //1pt=0.3759mm
                double TargetWdithPt = targetWidthCM / p;
                double TargetHeightPt = targetHeightCM / p;
                double[] bilv = new double[2];
                bilv[0] = TargetWdithPt / width_pt;
                bilv[1] = TargetHeightPt / height_pt;
                return (bilv[0] > bilv[1] ? bilv[1] : bilv[0]);
            }
    

       

  • 相关阅读:
    类成员函数的重载、覆盖和隐藏区别 (C++)(转)
    man时括号里的数字是啥意思
    Redis事务
    功能接口
    持久化方式
    宿主
    路由
    静态文件
    Log4Net 配置
    Redis命令与配置
  • 原文地址:https://www.cnblogs.com/DayDreamEveryWhere/p/7723133.html
Copyright © 2011-2022 走看看