首页 > 解决方案 > 如何使用 EZDXF 库添加不同比例的图像?

问题描述

我注意到“IMAGE 实体就像一个块参考,您可以多次使用它来将图像添加到具有不同比例和旋转的不同位置。” 在“图像”类的介绍中(参见:https ://ezdxf.readthedocs.io/en/master/dxfentities/image.html )。但我找不到任何参数来调整图像大小。例如,图像的原始大小是(3000x1691),当我使用 AutoCAD 加载这个图像的 dxf 文件时,我希望它的大小是(101x57)。有人能告诉我怎么做吗?对不起我的穷人英语。这是我的代码:


dwg = ezdxf.readfile('AC1015.dxf')# 2010

msp = dwg.modelspace()

imageWidth, imageHeight = get_image_size(imageFilePath)

#create layout
dwg.layers.new(name=layoutName, dxfattribs={'color': layoutColor})
my_layout = dwg.layers.get(layoutName)

my_image_def = dwg.add_image_def(filename=imageFilePath, size_in_pixel=(imageWidth,imageHeight))
my_image_def.dxf.resolution_units = 2

image_ = msp.add_image(insert=ucs.origin, size_in_units=(1,1),
                           image_def=my_image_def, rotation=0, dxfattribs={'layer': layoutName})

#save file
dwg.saveas(dxfoutfile)

我尝试更改“size_in_pixel”和“size_in_units”,但没有成功。如果你能帮助我,我将不胜感激。

标签: pythondxfezdxf

解决方案


推荐阅读