共通言語ランタイムを使用してIronPythonを使用してサムネイルイメージを作成しようとしています。IronPythonでCLRを使用してサムネイルイメージを作成する。デリゲートの問題を解決する
Visual Basicの背景から、私はIronPython内からCLRに委譲された関数を渡すというコンセプトに苦しんでいます。以下は
は私のコーディングです:
import os
import clr
# contains Image definition
clr.AddReference('System.Drawing')
from System.Drawing import Image
# contains Action and Func for delegation
clr.AddReference('System.Core')
from System import Func
# open image filename
objImageA = Image.FromFile('a.jpg')
# delegated function
def ImageAbortDelegate():
return False
objThumbImageAbort = Func[objImageA.GetThumbnailAbort](ImageAbortDelegate)
# for this example reduce image by 10 percent
intHeight = objImageA.Height/10
intWidth = objImageA.Width/10
# why is this failing?
objThumbImageA = objImageA.GetThumbnailImage(intHeight, intWidth, objThumbAbort, 0)
# gives error message TypeError: expected GetThumbnailImageAbort, got Func[GetThumbnailImageAbort]
'GetThumbnailImageAbort'はデリゲートを作成するので、' Func'でラップする必要はありません。 – David