使用 open xml 在 powerpoint 中设置图像大小
我正在使用本教程生成一个 ppt 文件 此处
步骤 4 描述了如何换出图像占位符。 我的图像具有不同的尺寸,这使得某些图像看起来有点太有趣了。
有什么方法可以调整占位符的大小以保持尺寸吗?
编辑:好的,更好的解释:用户可以上传自己的图像。图像存储在服务器上。我正在生成一个 ppt 文件,每张幻灯片有一个用户。每张幻灯片都会有一个图像(如果有的话)。我当然可以获取每个图像的尺寸,但是如何用占位符以外的其他尺寸的图像替换占位符?
Im am generating a ppt-file using this tutorial here
Step 4 describes how to swap out the image placeholder.
My images has different dimensions, which makes some images look a little bit too funny.
Is there any way to resize the placeholder so it can keep the dimensions?
Edit: Ok, a better explanation: users can upload images of them selves. The images are stored on the server. I am generating a ppt-file with one user per slide. And for every slide there will be an image, if any. I can of course get the dimensions of every image, but how do I replace the placeholder with an image of another dimension than the placeholder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我无法根据该教程告诉您,但我可以告诉您它是在 Open XML 中完成的(即不是 SDK)。
您的图片将包含一个包含一组值的
xfrm
元素,如下所示:您要更改的值是
cx
和cy
代码>a:ext。从System.Drawing.Image
对象中获取新图片的尺寸(高和宽),然后将每个值乘以 12700。因此,如果图片的宽度为 400 像素,则 <a:ext
的 code>cx 值为 (400 x 12700 = 5080000)。Well, I can't tell you based on that tutorial, but I can tell you where it is done in Open XML (i.e. not the SDK).
Your picture will have an
xfrm
element with a set of values, like this:The values you want to change are the
cx
andcy
ofa:ext
. Take your new picture's dimensions (h and w) from like aSystem.Drawing.Image
object and take each of the values and multiply by 12700. So if the width of the picture is 400 pixels, thecx
value ofa:ext
will be (400 x 12700 = 5080000).我就是这样做的:
假设您有
SlidePart
在我的例子中,我想检查图片的替代标题,如果它与我的键匹配,则替换它们。
现在我们检查所有图像:
现在在循环中我们查找
Transform2D
并用我们的值修改它:这个函数如下所示:
需要注意的重要一点是
EMU perinch 是
914400
。在大多数情况下,您只需将其除以96
,但对于某些显示器而言,情况有所不同。因此,最好将DPI
分为x
和y
。This is how I did it:
lets assume you have your
SlidePart
In my case I wanted to check for the alt title of the pictures and replace them if it matches to my key.
now we check all the images:
now in the loop we look for
Transform2D
and modify it with our value:And this function looks like this:
Important thing to note is that
EMU per inch
is914400
. In most cases you just need to divide it by96
, but for some monitors it is different. Therefore it is best to divide it theDPI
forx
andy
.