【Python】【Rhinocommon】ex_addbackgroundbitmap.py——在视口中添加位图背景

案例:ex_activeviewport.py

import Rhino
import scriptcontext
import System.Windows.Forms.DialogResult
import System.Drawing.Image

def AddBackgroundBitmap():
    # Allow the user to select a bitmap file
    fd = Rhino.UI.OpenFileDialog()
    fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"
    if fd.ShowDialog()!=System.Windows.Forms.DialogResult.OK:
        return Rhino.Commands.Result.Cancel

    # Verify the file that was selected
    image = None
    try:
        image = System.Drawing.Image.FromFile(fd.FileName)
    except:
        return Rhino.Commands.Result.Failure

    # Allow the user to pick the bitmap origin
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Bitmap Origin")
    gp.ConstrainToConstructionPlane(True)
    gp.Get()
    if gp.CommandResult()!=Rhino.Commands.Result.Success:
        return gp.CommandResult()

    # Get the view that the point was picked in.
    # This will be the view that the bitmap appears in.
    view = gp.View()
    if view is None:
        view = scriptcontext.doc.Views.ActiveView
        if view is None: return Rhino.Commands.Result.Failure

    # Allow the user to specify the bitmap with in model units
    gn = Rhino.Input.Custom.GetNumber()
    gn.SetCommandPrompt("Bitmap width")
    gn.SetLowerLimit(1.0, False)
    gn.Get()
    if gn.CommandResult()!=Rhino.Commands.Result.Success:
        return gn.CommandResult()

    # Cook up some scale factors
    w = gn.Number()
    h = w * (image.Width / image.Height)

    plane = view.ActiveViewport.ConstructionPlane()
    plane.Origin = gp.Point()
    view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, False, False)
    view.Redraw()
    return Rhino.Commands.Result.Success

if __name__=="__main__":
    AddBackgroundBitmap()

功能

请添加图片描述

解析:ex_addbackgroundbitmap.py

这是一段使用Rhino.Python脚本编写的代码,用于在Rhino软件中添加背景位图。代码的具体功能如下:

  1. 弹出对话框,允许用户选择一个位图文件(bmp、png或jpg格式)作为背景图像。
  2. 验证所选文件是否有效,如果无效则返回失败。
  3. 允许用户选择位图在Rhino文档中的位置和大小,并将其添加到当前视图中作为背景图像。

下面是代码的具体解释:

  • 首先导入Rhino和System.Windows.Forms命名空间以及System.Drawing.Image类。
  • 定义AddBackgroundBitmap()函数,该函数用于添加背景位图。
  • 使用Rhino.UI.OpenFileDialog()方法弹出文件对话框,允许用户选择位图文件,并设置过滤器以限制文件类型。
  • 验证所选文件是否有效,如果无效则返回失败。
  • 使用Rhino.Input.Custom.GetPoint()方法允许用户在Rhino文档中选择位图的位置,并获取选择点所在的视图。
  • 使用Rhino.Input.Custom.GetNumber()方法允许用户选择位图的大小,并计算位图的宽高比。
  • 获取当前视图的构造平面,并将其设置为选择点的位置。
  • 使用view.ActiveViewport.SetTraceImage()方法将位图添加到当前视图中作为背景图像,并指定位图的位置、大小和是否重复。
  • 最后使用view.Redraw()方法刷新当前视图以显示新添加的背景图像。

在代码中,如果用户取消选择文件或操作失败,则会返回Rhino.Commands.Result.Cancel或Rhino.Commands.Result.Failure。如果操作成功,则返回Rhino.Commands.Result.Success。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要将频 `home_loop_720p.mp4` 作为人工智能网站的首页背景循环播放,您可以按照以下步骤进行操作: 1. 将频文件 `home_loop_720p.mp4` 放置在您网站的适当位置。 2. 在您的 CSS 文件中,为首页的容器元素创建一个类选择器,例如 `.home-section`。 3. 使用 CSS 属性 `background` 将频作为容器的背景,并设置循环播放的样式。在这里,我们使用 `background-size: cover;` 来确保频填充整个容器。 ```css .home-section { height: 100vh; /* 设置容器高度为口高度 */ background: url(home_loop_720p.mp4) no-repeat; background-size: cover; -webkit-background-size: cover; /* 兼容性设置 */ -moz-background-size: cover; /* 兼容性设置 */ -o-background-size: cover; /* 兼容性设置 */ background-repeat: no-repeat; background-position: center center; animation: playVideo 10s infinite; /* 通过动画实现循环播放 */ } @keyframes playVideo { 0% { background-position: 0% 0%; } 100% { background-position: 100% 100%; } } ``` 这段 CSS 代码将频作为背景,使用 `animation` 属性设置了一个名为 `playVideo` 的动画,持续时间为 10 秒,并且无限循环播放。`@keyframes` 定义了动画的关键帧,以实现从起始位置到结束位置的背景位置变化。 4. 在您的 HTML 文件中,将首页的容器元素添加到主页部分,并设置类选择器为先前定义的类选择器,如 `.home-section`。 ```html <section class="home-section"> <!-- 其他主页内容 --> </section> ``` 通过这些步骤,您就可以将频作为人工智能网站首页的背景,并实现循环播放的效果。请确保频文件的路径正确,并根据需求调整 CSS 中的其他样式属性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hmywillstronger

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值