簡體   English   中英

maya Python比例圖片

[英]Maya Python scale picture

如何縮放圖片以適合窗口/布局?

在此處輸入圖像描述

使用下面的代碼,原始圖像實際上並沒有放大到 300px,而是以原始圖像大小顯示。

import maya.cmds as cmds

if (cmds.window(window1, exists=True)):
    cmds.deleteUI(window1)

window1 = cmds.window(w=300, h=300)
layout = cmds.columnLayout(w=300, h=300)
cmds.picture( image='image.png', w=300, h=300)

cmds.showWindow( window1 )

嘗試這個

import maya.OpenMaya as om

def resize_image(source_image, output_image, width, height):

    image = om.MImage()
    image.readFromFile(source_image)

    image.resize( width, height )
    image.writeToFile(output_image, 'png')


resizeImage('<source_image.png>','<output_image.png>', 300, 300)

我已經使用 iconTextButton 來設置具有不同寬度和高度的圖像。 使用 adjustableColumn=False 設置圖像的寬度/高度。 您也可以嘗試iconTextStaticLabel cmd。希望這對您有用..

import maya.cmds as cmds

if cmds.window('Test',exists=True):
   cmds.deleteUI('Test')
  
cmds.window('Test',title='Test Image', bgc=[0.266, 0.266, 0.266], widthHeight=[600,400], sizeable = True)
parentLayout = cmds.columnLayout(adjustableColumn=False)
cmds.iconTextButton(style="iconOnly",image1='Capture.png',p=parentLayout,w=150,h=150)
cmds.setParent('..')
cmds.showWindow('Test')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM