Sketchup API使用给定路径获取图像的宽度和高度

时间:2014-02-21 17:41:27

标签: ruby sketchup

我需要获得给定路径的图像宽度和高度。 这是我的详细代码

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

我需要一种在给定路径的代码中获取old_width和old_height值的方法。 谢谢你

1 个答案:

答案 0 :(得分:1)

您无需指定height,它是可选的。如果您仅指定width,则会根据图片的比例自动调整height

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