Sketchup API Get the width and height of image with given path

泪湿孤枕 提交于 2019-12-13 03:37:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!