Selon MSDN, Create()
nécessite un paramètre de chaîne avec le chemin ou le nom de fichier pour un MDI ou TIF-documents, ce qui signifie qu'il ne sera pas accepter le System.Drawing.Image
-object que vous obtenez de GetImage()
. Pour contourner le problème, vous pouvez enregistrer l'image stockée dans le Presse-papiers dans un fichier temporaire et essayer de le charger. Ex.
#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)
Si Create()
se plaint de nom de fichier (extension manquante), puis il suffit de l'ajouter à la température-filepath:.
$filepath = [System.IO.Path]::GetTempFileName() + ".tif"
Vous pouvez également appuyer copier sur un fichier (ex ctrl + c dans le fichier Explorer) et récupérez ce chemin. Exemple:
#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)
}
Avez-vous chargé l'assemblage winforms en premier? ('Add-Type -Assembly System.Windows.Forms') –