问题
I need to get width and height of image with given path. Here is my detail code
path = UI.openpanel("Open Image File","/","*.jpg;*.png;*.jpeg")
if(path != nil)
#get the original width of image
old_width = ??????
#get the original height of image
old_height = ??????
#get the orginal rate of image
rate = old_width.to_f / old_height_to_f
#then import image into model as a Image entity
point = Geom::Point3d.new 0,10,0
objImage = entities.add_image path, point , 318,318/rate
end
I need a way to get value of old_width and old_height in this code with given path. Thanks you
回答1:
You won't need to specify the height
, it is optional. If you specify just the width
the height
will be adjusted automatically based on the proportions of the image.
path = UI.openpanel("Open Image File", "/", "*.jpg;*.png;*.jpeg")
if !path.nil?
point = Geom::Point3d.new(0, 10, 0)
image = entities.add_image(path, point, 318)
end
来源:https://stackoverflow.com/questions/21941422/sketchup-api-get-the-width-and-height-of-image-with-given-path