Question
2011 Scripting Games : Advanced Event 8
- Matthew BETTON
- Auteur du sujet
- Hors Ligne
- Membre platinium
-
- Messages : 968
- Remerciements reçus 0
Ci-après le script que j'ai posté lors des Scripting Games 2011, dans le cadre de l'Advanced Event 8.
Le scénario était le suivant :
Event scenario
You have a number of pictures stored in a series of folders. Some of the images have a lot of metadata associated with them, others do not. You are planning to share some of the pictures with friends, but because the images are extremely large, you need to resize them to a size that is suitable for email. You would like to be able to remove all metadata from files that you want to share. You decide to create a script that will show a graphical interface displaying a picture on one side and the metadata associated with the picture on the other side. The graphical interface should also contain a button that is named something like Prepare to share. When clicked, this button will resize the image, remove all of the metadata associated with the file, and save the new file under a new name that prepends the word SHARE and an underscore in this fashion: SHARE_originalfilename.
Design points
You are free to use existing modules, controls, and so on that are freely available; however, you cannot provide a solution that requires commercial non-Microsoft software. But if you take an external dependency in your solution you MUST check for this requirement in your script.
You are free to use any approach you wish to create your graphical solution.
Extra points for offering to automatically download and install any external dependencies.
Your solution should allow the user to set the initial folder to gather the images.
Your solution should allow the user to set a different folder to save the SHARE_ images.
Extra points for adding a graphical folder picker to allow the user to select the initial folder.
Extra points for remembering configuration preferences.
Extra points for allowing the user to easily process all of the files in the initial folder.
Le script que j'avais posté (une solution) :
[code:1]#
# 2011 Scripting Games : Advanced Event 8
# Script : Set-SharedImages.ps1
# Author : Matthew BETTON (France / Basse-Normandie / Manche (50))
# Date : 04/12/2011
# Synopsis : Use PowerShell to Remove Metadata and Resize Images
#
<#
.SYNOPSIS
Remove Metadata and resize image(s) before sharing it (them).
.DESCRIPTION
Set-SharedImages.ps1 uses Windows Presentation Foundation (WPF) for displaying a user interface.
This Graphical User Interface allows the user to :
- Browse a directory for images (*.jpg, *.bmp, *.gif, *.png) ;
- Displays Metadata informations for each image ;
- Prepare one image or all images. For each image :
- An output resized image is generated (640 x 480) ;
- Metadata informations from original image are not kept ;
- New image is saved as \"SHARE_[].JPG\", in selected destination folder.
To work correctly this script needs :
- \"PowerShell Community Extension\" Module : if not present in the modules folder,
the script displays a message to inform the user where he can find it.
The Pscx module is needed for resizing operations (Import-Bitmap, Resize-Bitmap and Export-Bitmap).
- \"Microsoft Windows Image Acquisition Library v2.0\" library : if not present, the script automatically
downloads it and install it, in the script current directory.
The WIA library is needed for retrieving and displaying image file metadata.
The script saves parameters (Source and destination folders) in the user's registry, under
HKEY_CURRENT_USER\Software\ScriptingGames2011\ShareImages.
You can use $DebugPreference variable in order to display DEBUG informations.
Set $DebugPreference to \"Continue\" and the script will display DEBUG messages.
#>
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(\"System.Drawing\"«») | Out-Null
[reflection.assembly]::loadwithpartialname(\"System.Windows.Forms\"«») | Out-Null
#endregion
#region Variables
# This variables will be usefull for displaying MessageBox informations
$Global:MsgBox = [Windows.Forms.MessageBox]
$Global:BoutonOK = [Windows.Forms.MessageBoxButtons]::OK
$Global:MBoxIconInformation = [Windows.Forms.MessageBoxIcon]::Information
$Global:MBoxIconExclamation = [Windows.Forms.MessageBoxIcon]::Exclamation
$Global:MBoxIconError = [Windows.Forms.MessageBoxIcon]::Error
$Global:MBoxIconWarning = [Windows.Forms.MessageBoxIcon]::Warning
# Gets working script directory
$Global:«»ScriptPath = split-path $MyInvocation.mycommand.path
#endregion
#region Import PowerShell Community Extensions Module
Write-Debug \"Loading Pscx module ...\"
$PscxModule = Get-Module Pscx -ErrorAction SilentlyContinue
if(-not $PscxModule){
try{
Import-Module Pscx -ErrorAction Stop
}
catch{
$Msg = \"Can't load 'PowerShell Community Extensions' module.`nPlease download Pscx module at 'pscx.codeplex.com/' and install it.\"
$MsgBox::«»show($Msg,\"Module not found\", $BoutonOK, $MBoxIconError) | Out-Null
exit
}
}
#endregion
#region Functions
# Save parameters to registry HKCU (in current user connected registry)
Function Set-ParametersToRegistry(){
Write-Debug \"Function Set-ParametersToRegistry\"
$StrRootKey = \"HKCU:\Software\ScriptingGames2011\"
$StrSubKey = \"$StrRootKey\ShareImages\"
$SGkey = Get-Item $StrRootKey -ErrorAction SilentlyContinue
if(-not $SGkey){
Write-Debug \"Registry key $StrRootKey has not been found\"
Write-Debug \"Creating registry keys ...\"
New-Item -Type Directory $StrRootKey | Out-Null
New-Item -Type Directory $StrSubKey | Out-Null
}
else{
$SIkey = Get-Item $StrSubKey -ErrorAction SilentlyContinue
if(-not $SIkey){
Write-Debug \"Registry key $StrSubKey has not been found\"
Write-Debug \"Creating registry key ...\"
New-Item -Type Directory $StrSubKey | Out-Null
}
}
Write-Debug \"Saving parameters to registry values ...\"
Set-ItemProperty -Path $StrSubKey -name \"ImageSourcePath\" -value $textBoxSourcePath.text -Force
Set-ItemProperty -Path $StrSubKey -name \"ImageDestinationPath\" -value $textBoxDestinationPath.text -Force
}
# Load parameters from registry HKCU (in current user connected registry)
Function Get-ParametersFromRegistry(){
Write-Debug \"Function Get-ParametersFromRegistry\"
$StrRootKey = \"HKCU:\Software\ScriptingGames2011\"
$StrSubKey = \"$StrRootKey\ShareImages\"
$SIkey = Get-ItemProperty -Path $StrSubKey -ErrorAction SilentlyContinue
if($SIkey){
$ImageSourcePath = $null
$ImageDestinationPath = $null
$ImageSourcePath = $SIkey.ImageSourcePath
$ImageDestinationPath = $SIkey.ImageDestinationPath
}
else{
Set-ParametersToRegistry
}
if($ImageSourcePath -and $ImageDestinationPath){
Write-Debug \"Values exist at $StrSubKey\"
$textBoxSourcePath.text = $ImageSourcePath
$textBoxDestinationPath.text = $ImageDestinationPath
}
else{
Write-Debug \"Values for source and destination folders do not exist at $StrSubKey\"
Write-Debug \"Initializing registry values ...\"
$textBoxSourcePath.text = $ScriptPath
$textBoxDestinationPath.text = $ScriptPath
Set-ParametersToRegistry
}
}
# This function loads 'Wia.ImageFile' object.
# If can't load, trying to download, unzip and register dll file
Function Get-WIALibrary(){
param(
[parameter(Mandatory=$true)]
[String]$Folder,
[parameter(Mandatory=$false)]
[String]$DLUrl = \"download.microsoft.com/download/WinXPHom.../WIAAutSDK.zip\",
[parameter(Mandatory=$false)]
[String]$DLZipFile = \"$Folder\temp_file.zip\",
[parameter(Mandatory=$false)]
[String]$DLLFile = \"wiaaut.dll\"
)
Write-Debug \"Function Get-WIALibrary\"
$test = $true
# test call of WIA library
try{
$Global:objWiaImageFile = New-Object -ComObject Wia.ImageFile
}
catch{
Write-Debug \"Can't load 'Wia.ImageFile' object... We need to download and install it\"
$test = $false
}
if($test){
Write-Debug \"'Microsoft Windows Image Acquisition Library v2.0' was loaded successfully\"
return $null
}
# Download zip file from source
try{
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($DLUrl, $DLZipFile)
$WebClient.Dispose()
}
catch{
return \"An error has occured while downloading '$DLUrl' : $($_.exception.Message)\"
}
# Unzip dll file from zip file
try{
$objShell = new-object -com shell.application
$zipFolder = $objShell.namespace($DLZipFile)
$sourceDLLFile = $zipFolder.parsename($DLLFile)
$targetFolder = $objShell.namespace($Folder)
$targetFolder.CopyHere($sourceDLLFile)
$objShell = $null
$zipFolder = $null
$sourceDLLFile = $null
$targetFolder = $null
Remove-Item $DLZipFile
}
catch{
return \"An error has occured while unziping '$DLZipFile' : $($_.exception.Message)\"
}
# silently registering DLL file
try{
Start-Process -FilePath \"cmd.exe\" -ArgumentList \"/c regsvr32.exe /s $Folder\$DLLFile\" -ErrorAction Stop
}
catch{
return \"An error has occured while loading $DLLFile : $($_.exception.Message)\"
}
# Sleep, time to register new dll
sleep -Seconds 2
# test call of WIAAUT library
try{
$Global:objWiaImageFile = New-Object -ComObject Wia.ImageFile
}
catch{
return \"An error has occured while loading Wia.ImageFile : $($_.exception.Message)\"
}
Write-Debug \"'Microsoft Windows Image Acquisition Library v2.0' was loaded successfully\"
return $null
}
# This function loads images from a folder
Function Get-PicturesFromFolder(){
param(
[parameter(Mandatory=$true)]
[string]$Path
)
Write-Debug \"Function Get-PicturesFromFolder\"
Write-Debug \"'-Path' parameter value : $Path\"
$Global:ImageFiles = $null
$Global:CurrentImage=$null
try{
$Global:ImageFiles = Get-ChildItem \"$Path\*.*\" -Include *.jpg, *.bmp, *.gif, *.png -Exclude Share_* -ErrorAction Stop | %{$_.FullName}
}
catch{
$Msg = \"An error has ocured while trying to load images in '$Path' directory ...\"
$MsgBox::«»show($Msg,\"Error loading image(s)\", $BoutonOK, $MBoxIconError) | Out-Null
return $null
}
if(-not $ImageFiles){
$Msg = \"No images found in '$Path' directory ...`n`nPlease select a new source path that contains one or more image :«»)\"
$MsgBox::«»show($Msg,\"File not found\", $BoutonOK, $MBoxIconWarning) | Out-Null
return $null
}
return $Path
}
# Function for resizing an image and save it as SHARE_'image'.Jpeg
Function Set-PreparedImage(){
param(
[parameter(Mandatory=$true)]
[string]$File,
[parameter(Mandatory=$true)]
[string]$Path,
[parameter(Mandatory=$false)]
[Int32]$Width=640,
[parameter(Mandatory=$false)]
[Int32]$Height=480,
[parameter(Mandatory=$false)]
[Int32]$Quality=10
)
Write-Debug \"Function Set-PreparedImage\"
if(-not (Test-Path $Path)){
$Msg = \"'$Path' has not been found !\"
$MsgBox::«»show($Msg,\"Path not found\", $BoutonOK, $MBoxIconError) | Out-Null
return $null
}
if((Test-Path $File)){
$CurrentFile = Get-Item -Path $File -ErrorAction SilentlyContinue
}
else{
$Msg = \"'$File' has not been found !\"
$MsgBox::«»show($Msg,\"File not found\", $BoutonOK, $MBoxIconError) | Out-Null
return $null
}
$NewFileName = \"$Path\SHARE_$($CurrentFile.Name)\"
Write-Debug \"NewFileName : $NewFileName\"
if(-not (Test-Path $NewFileName)){
$img = Import-Bitmap $File
[int]$currentWidth = $img.Width
[int]$currentHeight = $img.Height
# Resize image and save as (Keep aspect ratio for landscape or portrait image)
if($currentHeight -gt $currentWidth){
Import-Bitmap $CurrentFile.FullName | Resize-Bitmap -Height $Height -KeepAspectRatio | Export-Bitmap -path $NewFileName -Quality $Quality
}
else{
Import-Bitmap $CurrentFile.FullName | Resize-Bitmap -Width $Width -KeepAspectRatio | Export-Bitmap -path $NewFileName -Quality $Quality
}
return $true
}
}
# This function gets file metadata
Function Get-ImageMetadata(){
param(
[Parameter(Mandatory=$true)]
[string]$FilePath
)
Write-Debug \"Function Get-ImageMetadata\"
if(-not(Test-Path $FilePath)){
Write-Debug \"File has not been found !\" -ForegroundColor Red
return $null
}
try{
$file = Get-Item $FilePath -ErrorAction Stop
}
catch{
$Msg = \"Can't load file's Metadata ($FilePath)\"
$MsgBox::«»show($Msg,\"File not found\", $BoutonOK, $MBoxIconError) | Out-Null
}
Write-Debug \"Getting file metadata ...\"
$objShell = New-Object -com shell.application
$objFolder = $objShell.nameSpace($file.DirectoryName)
$item = $objFolder.parseName($file.Name)
$MetaDataTab = $null
$MetaDataTab = @()
for ($i = 0 ; $i -le 266; $i++){
if($objFolder.getDetailsOf($item, $i)){
$Data = \"\" | Select Name, Value
$Data.Name = $objFolder.getDetailsOf($objFolder.items, $i)
$Data.Value = $objFolder.getDetailsOf($item, $i)
$MetaDataTab += $Data
}
}
Write-Debug \"Getting image file metadata ...\"
$objWiaImageFile.LoadFile(\"$FilePath\"«»)
foreach($Property in $objWiaImageFile.Properties){
$Data = \"\" | Select Name, Value
$Data.Name = $Property.Name
if($Property.Value -is [System.__ComObject]){
$Data.Value = $Property.Value.Value
}
else{
$Data.Value = $Property.Value
}
$MetaDataTab += $Data
}
$objShell = $null
$objFolder = $null
$item = $null
return $MetaDataTab
}
# Load texts and color in status bar then refresh it
Function Set-StatusBar () {
param(
[Parameter(Mandatory=$true)]
[Drawing.Color]$Color,
[Parameter(Mandatory=$true)]
[String]$Text,
[Parameter(Mandatory=$true)]
[String]$sltext
)
Write-Debug \"Function Set-StatusBar\"
$status.BackColor = $color
$status.Text = $text
$slMessage.Text = $sltext
$form1.Refresh()
}
#endregion
##############
# MAIN SCRIPT
##############
Write-Debug \"Loading 'Microsoft Windows Image Acquisition Library v2.0' library ...\"
$WIALoadErr = Get-WIALibrary -Folder $ScriptPath
if($WIALoadErr){
$Msg = \"WIA library can't be loaded from your system :\"
$Msg += $WIALoadErr
$Msg += \"`nThis script can't work without this library.\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconError) | Out-Null
exit
}
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 13/04/2011 22:06
# Generated By: MATTHEW BETTON
########################################################################
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$ButtonPrepareAll = New-Object System.Windows.Forms.Button
$ButtonNext = New-Object System.Windows.Forms.Button
$ButtonBack = New-Object System.Windows.Forms.Button
$ButtonPrepareToShare = New-Object System.Windows.Forms.Button
$ButtonBrowseDestinationPath = New-Object System.Windows.Forms.Button
$ButtonBrowseSourcePath = New-Object System.Windows.Forms.Button
$textBoxDestinationPath = New-Object System.Windows.Forms.TextBox
$toolTip = New-Object System.Windows.Forms.ToolTip
$DestinationPathLabel = New-Object System.Windows.Forms.Label
$textBoxSourcePath = New-Object System.Windows.Forms.TextBox
$SourcePathLabel = New-Object System.Windows.Forms.Label
$DataGridViewMetaData = New-Object System.Windows.Forms.DataGridView
$pictureBox = New-Object System.Windows.Forms.PictureBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$statusStrip = new-object System.Windows.Forms.StatusStrip
$status = new-object System.Windows.Forms.ToolStripStatusLabel
$slMessage = new-object System.Windows.Forms.ToolStripStatusLabel
$StatusIcon = new-object System.Windows.Forms.ToolStripStatusLabel
#endregion Generated Form Objects
$Global:CurrentImageFile = $null
$Global:ImageFiles = $null
Get-ParametersFromRegistry
Write-Debug \"Loading images from $($textBoxSourcePath.Text) folder ...\"
Get-PicturesFromFolder -Path $textBoxSourcePath.Text | Out-Null
#
#Generated Event Script Blocks
#
$ButtonPrepareAll_OnClick=
{
if($ImageFiles){
foreach($Image in $ImageFiles){
Set-PreparedImage -File $Image -Path $textBoxDestinationPath.Text
Set-StatusBar \"Green\" \"Preparing images... \" \"Working\"
}
if($ImageFiles.count){
$Msg = \"$($ImageFiles.count) images have been prepared\"
}
else{
$Msg = \"One image has been prepared\"
}
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconInformation) | Out-Null
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
else{
$Msg = \"No image file has been found in $($textBoxDestinationPath.Text)\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconWarning) | Out-Null
Set-StatusBar \"yellow\" \"No image file loaded\" \"Warning\"
}
}
$ButtonNext_OnClick=
{
&$GetNextImageBlock
&$DisplayMetaDataBlock
}
$ButtonBack_OnClick=
{
&$GetBackImageBlock
&$DisplayMetaDataBlock
}
$GetNextImageBlock=
{
Write-Debug \"GetNextImageBlock\"
if($ImageFiles){
Set-StatusBar \"green\" \"Loading image file...\" \"Working...\"
if($ImageFiles.Count){
if($CurrentImageNumber -ne ($ImageFiles.Count - 1)){
$Global:CurrentImageNumber = $CurrentImageNumber + 1
$Global:CurrentImageFile = $ImageFiles[$CurrentImageNumber]
}
else{
$Global:CurrentImageNumber = 0
$Global:CurrentImageFile = $ImageFiles[$CurrentImageNumber]
}
}
else{
$Global:CurrentImageNumber = 0
$Global:CurrentImageFile = $ImageFiles
}
$pictureBox.Image = (Import-Bitmap (Get-Item $CurrentImageFile))
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
else{
$Msg = \"No file is currently loaded. Please select a folder containing images ...\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconWarning) | Out-Null
Set-StatusBar \"yellow\" \"No image file loaded\" \"Warning\"
}
}
$GetBackImageBlock=
{
Write-Debug \"GetBackImageBlock\"
if($ImageFiles){
if($ImageFiles.Count){
Set-StatusBar \"green\" \"Loading image file...\" \"Working...\"
if($CurrentImageNumber -ne 0){
$Global:CurrentImageNumber = $CurrentImageNumber - 1
$Global:CurrentImageFile = $ImageFiles[$CurrentImageNumber]
}
else{
$Global:CurrentImageNumber = $ImageFiles.Count - 1
$Global:CurrentImageFile = $ImageFiles[$CurrentImageNumber]
}
$pictureBox.Image = (Import-Bitmap (Get-Item $CurrentImageFile))
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
}
else{
$Msg = \"No file is currently loaded. Please select a folder containing images ...\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconWarning) | Out-Null
Set-StatusBar \"yellow\" \"No image file loaded\" \"Warning\"
}
}
$DisplayMetaDataBlock=
{
Write-Debug \"DisplayMetaDataBlock\"
if($ImageFiles){
Set-StatusBar \"green\" \"Loading image file MetaData...\" \"Working...\"
$CurrentMetaData = Get-ImageMetadata -FilePath $CurrentImageFile
$DataGridViewMetaData.rows.clear()
foreach($Metadata in $CurrentMetaData){
$row = (\"$($MetaData.Name)\", \"$($MetaData.Value)\"«»)
$dataGridViewMetaData.Rows.Add($row)
}
if($ImageFiles.count){
$toolTip.SetToolTip($pictureBox,\"$($CurrentImageFile) ($($CurrentImageNumber + 1 )/$($ImageFiles.count))\"«»)
}
else{
$toolTip.SetToolTip($pictureBox,\"$($CurrentImageFile) 1/1\"«»)
}
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
}
$ButtonPrepareToShare_OnClick=
{
Write-Debug \"ButtonPrepareToShare_OnClick\"
if($ImageFiles){
Set-StatusBar \"green\" \"Preparing image for file sharing...\" \"Working...\"
if($CurrentImageFile){
$result = Set-PreparedImage -File $CurrentImageFile -Path $textBoxDestinationPath.Text
if($result){
$Msg = \"$CurrentImageFile image has been prepared\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconInformation) | Out-Null
}
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
else{
$Msg = \"No file is currently loaded\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconWarning) | Out-Null
Set-StatusBar \"Yellow\" \"No file loaded\" \"Warning\"
}
}
else{
$Msg = \"No file is currently loaded\"
$MsgBox::«»show($Msg,$form1.text, $BoutonOK, $MBoxIconWarning) | Out-Null
Set-StatusBar \"Yellow\" \"No file loaded\" \"Warning\"
}
}
$ButtonBrowseSourcePath_OnClick=
{
Write-Debug \"ButtonBrowseSourcePath_OnClick\"
$app = new-object -com Shell.Application
$folder = $app.BrowseForFolder(0, \"Select a source folder :\", 0)
if ($folder) {
$textBoxSourcePath.text = $folder.Self.Path
Set-StatusBar \"Green\" \"Loading images from $($textBoxSourcePath.text)\" \"Working\"
Get-PicturesFromFolder -path $textBoxSourcePath.text | Out-Null
$Global:CurrentImageNumber = 0
if($ImageFiles){
if($ImageFiles.count){
$Global:CurrentImageFile = $ImageFiles[$CurrentImageNumber]
}
else{
$Global:CurrentImageFile = $ImageFiles
}
$pictureBox.Image = (Import-Bitmap (Get-Item $CurrentImageFile))
&$DisplayMetaDataBlock
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
else{
$Global:CurrentImageFile = \"\"
}
Set-StatusBar \"Green\" \"___\" \"Ready\"
}
$app = $null
}
$ButtonBrowseDestinationPath_OnClick=
{
Write-Debug \"ButtonBrowseDestinationPath_OnClick\"
$app = new-object -com Shell.Application
$folder = $app.BrowseForFolder(0, \"Select a destination folder :\", 0)
Set-StatusBar \"Green\" \"Selecting new destination path ...\" \"Working\"
if ($folder) {
$textBoxDestinationPath.text = $folder.Self.Path
}
Set-StatusBar \"Green\" \"___\" \"Ready\"
$app = $null
}
$handler_pictureBox1_Click=
{
#TODO: Place custom script here
if($CurrentImageFile){
Write-Debug \"Opening image file in associated program ...\"
Invoke-Item $CurrentImageFile
}
}
$handler_label1_Click=
{
#TODO: Place custom script here
}
$OnLoadForm_StateCorrection=
{
Write-Debug \"Form : OnLoadForm_StateCorrection\"
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
if($ImageFiles){
$Global:CurrentImageNumber = 0
if($ImageFiles.count){
$Global:CurrentImageFile = $ImageFiles[$CurrentImageNumber]
}
else{
$Global:CurrentImageFile = $ImageFiles
}
Set-StatusBar \"Green\" \"___\" \"Ready\"
&$DisplayMetaDataBlock
}
else{
Set-StatusBar \"Yellow\" \"No file loaded\" \"Warning\"
}
}
$OnClosing=
{
Write-Debug \"Form : Onclosing\"
Set-ParametersToRegistry
$Global:objWiaImageFile = $null
}
#
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 432
$System_Drawing_Size.Width = 705
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = \"form1\"
$form1.Text = \"Prepare Images before sharing it\"
$toolTip.AutoPopDelay = 5000
$toolTip.InitialDelay = 500
$toolTip.OwnerDraw = $true
$toolTip.ReshowDelay = 10
$ToolTip.BackColor = [System.Drawing.Color]::LightGoldenrodYellow
$ToolTip.IsBalloon = $true
#$toolTip.Draw += New-Object System.Windows.Forms.DrawToolTipEventHandler($toolTip.Draw)
#$toolTip.Popup += New-Object System.Windows.Forms.PopupEventHandler($toolTip.Popup)
$ButtonPrepareAll.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 510
$System_Drawing_Point.Y = 280
$ButtonPrepareAll.Location = $System_Drawing_Point
$ButtonPrepareAll.Name = \"ButtonPrepareAll\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 90
$ButtonPrepareAll.Size = $System_Drawing_Size
$ButtonPrepareAll.TabIndex = 10
$ButtonPrepareAll.Text = \"Prepare All\"
$ButtonPrepareAll.UseVisualStyleBackColor = $True
$ButtonPrepareAll.add_Click($ButtonPrepareAll_OnClick)
$toolTip.SetToolTip($ButtonPrepareAll,\"Prepare all images before sharing them ...\"«»)
$form1.Controls.Add($ButtonPrepareAll)
$ButtonNext.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 370
$System_Drawing_Point.Y = 280
$ButtonNext.Location = $System_Drawing_Point
$ButtonNext.Name = \"ButtonNext\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$ButtonNext.Size = $System_Drawing_Size
$ButtonNext.TabIndex = 9
$ButtonNext.Text = \"Next\"
$ButtonNext.UseVisualStyleBackColor = $True
$ButtonNext.add_Click($ButtonNext_OnClick)
$toolTip.SetToolTip($ButtonNext,\"Show next image ...\"«»)
$form1.Controls.Add($ButtonNext)
$ButtonBack.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 260
$System_Drawing_Point.Y = 280
$ButtonBack.Location = $System_Drawing_Point
$ButtonBack.Name = \"ButtonNext\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$ButtonBack.Size = $System_Drawing_Size
$ButtonBack.TabIndex = 9
$ButtonBack.Text = \"Back\"
$ButtonBack.UseVisualStyleBackColor = $True
$ButtonBack.add_Click($ButtonBack_OnClick)
$toolTip.SetToolTip($ButtonBack,\"Show previous image ...\"«»)
$form1.Controls.Add($ButtonBack)
$ButtonPrepareToShare.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 100
$System_Drawing_Point.Y = 280
$ButtonPrepareToShare.Location = $System_Drawing_Point
$ButtonPrepareToShare.Name = \"ButtonPrepareToShare\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$ButtonPrepareToShare.Size = $System_Drawing_Size
$ButtonPrepareToShare.TabIndex = 8
$ButtonPrepareToShare.Text = \"Prepare to share\"
$ButtonPrepareToShare.UseVisualStyleBackColor = $True
$ButtonPrepareToShare.add_Click($ButtonPrepareToShare_OnClick)
$toolTip.SetToolTip($ButtonPrepareToShare,\"Prepare current image before sharing it ...\"«»)
$form1.Controls.Add($ButtonPrepareToShare)
$ButtonBrowseDestinationPath.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 509
$System_Drawing_Point.Y = 380
$ButtonBrowseDestinationPath.Location = $System_Drawing_Point
$ButtonBrowseDestinationPath.Name = \"ButtonBrowseDestinationPath\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 26
$ButtonBrowseDestinationPath.Size = $System_Drawing_Size
$ButtonBrowseDestinationPath.TabIndex = 7
$ButtonBrowseDestinationPath.Text = \"...\"
$ButtonBrowseDestinationPath.UseVisualStyleBackColor = $True
$ButtonBrowseDestinationPath.add_Click($ButtonBrowseDestinationPath_OnClick)
$toolTip.SetToolTip($ButtonBrowseDestinationPath,\"Browse for a different destination folder ...\"«»)
$form1.Controls.Add($ButtonBrowseDestinationPath)
$ButtonBrowseSourcePath.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 509
$System_Drawing_Point.Y = 343
$ButtonBrowseSourcePath.Location = $System_Drawing_Point
$ButtonBrowseSourcePath.Name = \"ButtonBrowseSourcePath\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 26
$ButtonBrowseSourcePath.Size = $System_Drawing_Size
$ButtonBrowseSourcePath.TabIndex = 6
$ButtonBrowseSourcePath.Text = \"...\"
$ButtonBrowseSourcePath.UseVisualStyleBackColor = $True
$ButtonBrowseSourcePath.add_Click($ButtonBrowseSourcePath_OnClick)
$toolTip.SetToolTip($ButtonBrowseSourcePath,\"Browse for a different source folder ...\"«»)
$form1.Controls.Add($ButtonBrowseSourcePath)
$textBoxDestinationPath.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 169
$System_Drawing_Point.Y = 380
$textBoxDestinationPath.Location = $System_Drawing_Point
$textBoxDestinationPath.Name = \"textBoxDestinationPath\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 320
$textBoxDestinationPath.Size = $System_Drawing_Size
$textBoxDestinationPath.TabIndex = 5
$textBoxDestinationPath.Enabled = $false
$form1.Controls.Add($textBoxDestinationPath)
$DestinationPathLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 169
$System_Drawing_Point.Y = 366
$DestinationPathLabel.Location = $System_Drawing_Point
$DestinationPathLabel.Name = \"DestinationPathLabel\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$DestinationPathLabel.Size = $System_Drawing_Size
$DestinationPathLabel.TabIndex = 4
$DestinationPathLabel.Text = \"Destination path :\"
$form1.Controls.Add($DestinationPathLabel)
$textBoxSourcePath.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 169
$System_Drawing_Point.Y = 343
$textBoxSourcePath.Location = $System_Drawing_Point
$textBoxSourcePath.Name = \"textBoxSourcePath\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 320
$textBoxSourcePath.Size = $System_Drawing_Size
$textBoxSourcePath.TabIndex = 3
$textBoxSourcePath.Enabled = $false
$form1.Controls.Add($textBoxSourcePath)
$SourcePathLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 169
$System_Drawing_Point.Y = 327
$SourcePathLabel.Location = $System_Drawing_Point
$SourcePathLabel.Name = \"SourcePathLabel\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 170
$SourcePathLabel.Size = $System_Drawing_Size
$SourcePathLabel.TabIndex = 2
$SourcePathLabel.Text = \"Source path :\"
$SourcePathLabel.add_Click($handler_label1_Click)
$form1.Controls.Add($SourcePathLabel)
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_1 = New-Object System.Windows.Forms.DataGridViewTextBoxColumn
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_1.HeaderText = \"Name\"
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_1.Name = \"\"
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_1.Width = 130
$dataGridViewMetaData.Columns.Add($System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_1)|Out-Null
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_2 = New-Object System.Windows.Forms.DataGridViewTextBoxColumn
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_2.HeaderText = \"Value\"
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_2.Name = \"\"
$System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_2.Width = 187
$dataGridViewMetaData.Columns.Add($System_Windows_Forms_dataGridViewMetaDataTextBoxColumn_2)|Out-Null
$dataGridViewMetaData.ColumnHeadersDefaultCellStyle = $System_Windows_Forms_DataGridViewCellStyle
$dataGridViewMetaData.Name = \"dataGridViewMetaData\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 320
$System_Drawing_Size.Height = 240
$dataGridViewMetaData.Size = $System_Drawing_Size
$dataGridViewMetaData.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 373
$System_Drawing_Point.Y = 13
$dataGridViewMetaData.Location = $System_Drawing_Point
$dataGridViewMetaData.ColumnHeadersVisible = $false
$dataGridViewMetaData.RowHeadersVisible = $false
$dataGridViewMetaData.TabIndex = 0
$dataGridViewMetaData.readonly = $true
$dataGridViewMetaData.add_CellContentClick($handler_dataGridViewMetaData_CellContentClick)
$form1.Controls.Add($dataGridViewMetaData)
$pictureBox.DataBindings.DefaultDataSourceUpdateMode = 0
#$pictureBox.ImageLocation = \"$ScriptPath\"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 12
$pictureBox.Location = $System_Drawing_Point
$pictureBox.Name = \"pictureBox\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 240
$System_Drawing_Size.Width = 320
$pictureBox.Size = $System_Drawing_Size
$pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
$pictureBox.TabIndex = 0
$pictureBox.TabStop = $False
$pictureBox.add_Click($handler_pictureBox1_Click)
if($ImageFiles){
if($ImageFiles.count){
$pictureBox.ImageLocation = $ImageFiles[0]
}
else{
$pictureBox.ImageLocation = $ImageFiles
}
}
$form1.Controls.Add($pictureBox)
#region StatusBar Code Form
$statusStrip.Location = new-object System.Drawing.Point(0, 463)
$statusStrip.Name = \"statusStrip\"
$statusStrip.Size = new-object System.Drawing.Size(629, 22);
$statusStrip.TabIndex = 70
$statusStrip.Text = \"statusStrip\"
$status.BorderStyle = 'SunkenInner'
$status.BorderSides = 'All'
$status.Text = \"\"
[void]$statusStrip.Items.add($status)
$slMessage.BorderStyle = 'SunkenInner'
$slMessage.BorderSides = 'All'
$slMessage.Text = \"\"
[void]$statusStrip.Items.add($slMessage)
$form1.Controls.Add($statusStrip)
#endregion StatusBar Code Form
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
$form1.add_Closing($OnClosing)
#Show the Form
$form1.ShowDialog()| Out-Null[/code:1]
Pour les personnes que cela intéresse, voici le lien vers une solution de l'expert .
Toutes les remarques seront les bienvenues !
Connexion ou Créer un compte pour participer à la conversation.
- Matthew BETTON
- Auteur du sujet
- Hors Ligne
- Membre platinium
-
- Messages : 968
- Remerciements reçus 0
excellent job.
... C'est vrai que j'y avais passé pas mal de temps (quelques longues soirées !
Connexion ou Créer un compte pour participer à la conversation.
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Discussions générales
- 2011 Scripting Games : Advanced Event 8