-1

を使用して、powershell でアプリからテキストを挿入しようとしています

$MODIObj = New-Object -ComObject MODI.Document
$MODIObj.Create($filepath)

クリップボードから画像を直接取得することはできますか? 私はこれを試しました:

$MODIObj.Create([System.Windows.Forms.Clipboard]::GetImage())

しかし、うまくいきません。ファイルを作成せずにそのようなことを試すことは可能ですか?

4

1 に答える 1

1

MSDNによるとCreate()、MDI または TIF ドキュメントのパスまたはファイル名を含む文字列パラメーターが必要です。System.Drawing.Imageつまり、取得した -object は受け入れられませんGetImage()。回避策として、クリップボードに保存されている画像を一時ファイルに保存し、それをロードしてみてください。元。

#Get image from clipboard
Add-Type -AssemblyName System.Windows.Forms
$i = [System.Windows.Forms.Clipboard]::GetImage()

#Save image to a temp. file
$filepath = [System.IO.Path]::GetTempFileName()
$i.Save($filepath)

#Create MODI.Document from filepath
$MODIObj = New-Object -ComObject MODI.Document
$MODIObj.Create($filepath)

Create()ファイル名 (拡張子がない) について不満がある場合は、それを一時ファイルパスに追加します。

$filepath = [System.IO.Path]::GetTempFileName() + ".tif"

ファイルのコピー (例: ファイル エクスプローラーの ctrl+c) を押して、そのパスを取得することもできます。例:

#Get image from clipboard
Add-Type -AssemblyName System.Windows.Forms

#If clipboard contains image-object
if([System.Windows.Forms.Clipboard]::ContainsImage()) {

    #Get image from clipboard
    $i = [System.Windows.Forms.Clipboard]::GetImage()

    #Save image to a temp. file
    $filepath = [System.IO.Path]::GetTempFileName()
    $i.Save($filepath)

} elseif ([System.Windows.Forms.Clipboard]::ContainsFileDropList()) {
    #If a file (or files) are stored in the clipboard (you have pressed ctrl+c/ctrl+x on file/files)
    $files = [System.Windows.Forms.Clipboard]::GetFileDropList()

    #Only using first filepath for this demo.
    #If you need to support more files, use a foreach-loop to ex. create multiple MODI.documents or process one at a time
    $filepath = $files[0]
}

#If filepath is defined
if($filepath) {
    #Create MODI.Document from filepath
    $MODIObj = New-Object -ComObject MODI.Document
    $MODIObj.Create($filepath)
}
于 2016-05-21T10:10:42.843 に答える