2019-03-22 23:53:20 +01:00
using Microsoft.VisualBasic.FileIO ;
using Mk0.GUI.Banner ;
2019-04-05 10:52:47 +02:00
using Mk0.Software.ImageSorter.Properties ;
2019-03-22 23:53:20 +01:00
using Mk0.Tools.Calculation ;
2019-04-05 10:52:47 +02:00
using Mk0.Tools.FileAssociaton ;
2019-03-22 23:53:20 +01:00
using Mk0.Tools.Images ;
using Mk0.Tools.Randomization ;
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Diagnostics ;
using System.Drawing ;
using System.Drawing.Imaging ;
using System.IO ;
using System.Linq ;
using System.Threading ;
using System.Windows.Forms ;
2019-12-27 23:42:36 +01:00
using Mk0.Software.OnlineUpdater ;
2019-03-22 23:53:20 +01:00
namespace Mk0.Software.ImageSorter
{
public partial class Main : Form
{
public string quellPath = "" ;
public string zielPath = "" ;
private string [ ] fileTypes = { "jpg" , "png" , "jpeg" , "gif" , "tif" , "tiff" , "bmp" } ;
private int moved = 0 ;
private int imageIndex ;
private List < Button > buttons = new List < Button > ( ) ;
private List < string > images = new List < string > ( ) ;
private List < string > history = new List < string > ( ) ;
private bool moving ;
private bool moveable = false ;
private Point startLocation ; //verschieben
2019-04-05 11:53:41 +02:00
private Cursor grabCursor = new Cursor ( new MemoryStream ( Resources . grab ) ) ;
private Cursor grabbingCursor = new Cursor ( new MemoryStream ( Resources . grabbing ) ) ;
2019-03-22 23:53:20 +01:00
private double xFaktor = 0.0 ;
private double yFaktor = 0.0 ;
private static object locker = new object ( ) ;
private Thread folderThread ;
private bool threadIsRunning = false ;
private Banner banner ;
private string startuppath ;
private string startupimage ;
2019-03-30 14:07:41 +01:00
public string [ ] Args ;
2019-08-07 15:55:48 +02:00
private System . Timers . Timer t1 = new System . Timers . Timer ( 1200 ) ;
2020-01-12 09:37:11 +01:00
private FormWindowState lastState = FormWindowState . Minimized ;
2020-01-19 08:40:43 +01:00
private string defaultWindowName ;
2019-03-22 23:53:20 +01:00
2019-03-30 14:07:41 +01:00
public Main ( )
2019-03-22 23:53:20 +01:00
{
InitializeComponent ( ) ;
2020-01-20 12:03:22 +01:00
defaultWindowName = Text ;
2019-08-15 20:31:28 +02:00
banner = new Banner ( components , panelBanner , pictureBoxBanner1 , pictureBoxBanner2 , labelBanner1 , labelBanner2 ) ;
pictureBoxImage . Cursor = grabCursor ;
2019-03-22 23:53:20 +01:00
DoubleBuffered = true ;
SetDefaultPath ( ) ;
2019-04-02 17:36:31 +02:00
comboBoxZoom . SelectedIndex = Properties . Settings . Default . zoom ;
2019-04-05 21:18:55 +02:00
2019-12-27 14:59:29 +01:00
//file assoc prüfen und in einstellungen richtig setzen
if ( FileAssociation . Check ( "Image_Sorter_JPG" , Application . ExecutablePath , "JPG Bild" , $@"{Application.StartupPath}\AssocIcons\jpg.ico" ) & &
FileAssociation . Check ( "Image_Sorter_PNG" , Application . ExecutablePath , "PNG Bild" , $@"{Application.StartupPath}\AssocIcons\png.ico" ) & &
FileAssociation . Check ( "Image_Sorter_GIF" , Application . ExecutablePath , "GIF Bild" , $@"{Application.StartupPath}\AssocIcons\gif.ico" ) & &
FileAssociation . Check ( "Image_Sorter_JPEG" , Application . ExecutablePath , "JPEG Bild" , $@"{Application.StartupPath}\AssocIcons\jpeg.ico" ) & &
FileAssociation . Check ( "Image_Sorter_BMP" , Application . ExecutablePath , "BMP Bild" , $@"{Application.StartupPath}\AssocIcons\bmp.ico" ) & &
FileAssociation . Check ( "Image_Sorter_TIF" , Application . ExecutablePath , "TIF Bild" , $@"{Application.StartupPath}\AssocIcons\tif.ico" ) & &
FileAssociation . Check ( "Image_Sorter_TIFF" , Application . ExecutablePath , "TIFF Bild" , $@"{Application.StartupPath}\AssocIcons\tiff.ico" ) )
{
Properties . Settings . Default . fileAssociation = true ;
}
else
{
Properties . Settings . Default . fileAssociation = false ;
}
Properties . Settings . Default . Save ( ) ;
2019-03-30 14:07:41 +01:00
}
2019-04-05 10:52:47 +02:00
2019-03-30 14:07:41 +01:00
private void Main_Load ( object sender , EventArgs e )
{
if ( Args ! = null )
2019-04-05 10:52:47 +02:00
{
2019-03-30 14:07:41 +01:00
ProcessParameters ( null , Args ) ;
Args = null ;
}
2020-01-20 12:03:22 +01:00
2019-12-27 23:42:36 +01:00
AutoUpdater . ShowSkipButton = false ;
2020-04-27 18:57:57 +02:00
AutoUpdater . Start ( "https://www.kmpr.at/update/imagesorter.xml" ) ;
2019-03-30 14:07:41 +01:00
}
2019-04-05 10:52:47 +02:00
2019-03-30 14:07:41 +01:00
public delegate void ProcessParametersDelegate ( object sender , string [ ] args ) ;
public void ProcessParameters ( object sender , string [ ] args )
{
if ( args ! = null & & args . Length ! = 0 )
{
if ( ! string . IsNullOrEmpty ( args [ 0 ] ) & & File . Exists ( args [ 0 ] ) )
{
startuppath = Path . GetDirectoryName ( args [ 0 ] ) ;
startupimage = Path . GetFileName ( args [ 0 ] ) ;
if ( ! string . IsNullOrEmpty ( startuppath ) & & File . Exists ( startuppath ) )
{
startuppath = Path . GetDirectoryName ( startuppath ) ;
startupimage = Path . GetFileName ( startuppath ) ;
}
SetDefaultPath ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( GetImageIndex ( Path . Combine ( startuppath , startupimage ) ) ) ;
2019-10-26 14:48:15 +02:00
if ( WindowState ! = FormWindowState . Normal | | WindowState ! = FormWindowState . Maximized )
{
2020-01-12 09:37:11 +01:00
if ( lastState ! = FormWindowState . Minimized ) { WindowState = lastState ; } else { WindowState = FormWindowState . Normal ; }
2019-10-26 14:48:15 +02:00
}
2020-01-12 09:37:11 +01:00
Activate ( ) ;
2019-10-26 14:48:15 +02:00
BringToFront ( ) ;
2020-01-12 09:37:11 +01:00
TopMost = true ;
TopMost = false ;
2019-03-30 14:07:41 +01:00
}
2019-04-05 10:52:47 +02:00
}
}
/// <summary>
/// Extrahiert die Icons für die Fileassociation
/// </summary>
private void ExtractAssocIcons ( )
{
Directory . CreateDirectory ( $@"{Application.StartupPath}\AssocIcons" ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\jpg.ico" , Resources . jpg ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\png.ico" , Resources . png ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\gif.ico" , Resources . gif ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\jpeg.ico" , Resources . jpeg ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\bmp.ico" , Resources . bmp ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\tif.ico" , Resources . tif ) ;
WriteResource ( $@"{Application.StartupPath}\AssocIcons\tiff.ico" , Resources . tiff ) ;
}
/// <summary>
/// Helfer um Resources auf die Platte zu schreiben
/// </summary>
/// <param name="path">Zielpfad</param>
/// <param name="icon">Resource</param>
private void WriteResource ( string path , Icon icon )
{
using ( var fileStream = new FileStream ( path , FileMode . Create ) )
{
icon . Save ( fileStream ) ;
}
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Default: Lädt das erste Bild
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_Shown ( object sender , EventArgs e )
{
2020-01-10 21:27:04 +01:00
if ( Properties . Settings . Default . fullScreen )
2019-03-22 23:53:20 +01:00
{
2020-01-10 21:27:04 +01:00
WindowState = FormWindowState . Maximized ;
2019-03-22 23:53:20 +01:00
}
2020-01-10 21:27:04 +01:00
else
2019-03-22 23:53:20 +01:00
{
2020-01-10 21:27:04 +01:00
if ( Properties . Settings . Default . lastHeight > = MinimumSize . Height )
{
Height = Properties . Settings . Default . lastHeight ;
}
if ( Properties . Settings . Default . lastWidth > = MinimumSize . Width )
{
Width = Properties . Settings . Default . lastWidth ;
}
if ( Properties . Settings . Default . lastTop < = Screen . PrimaryScreen . Bounds . Height & & Properties . Settings . Default . lastTop > = 0 )
{
Top = Properties . Settings . Default . lastTop ;
}
if ( Properties . Settings . Default . lastLeft < = Screen . PrimaryScreen . Bounds . Width & & Properties . Settings . Default . lastLeft > = 0 )
{
Left = Properties . Settings . Default . lastLeft ;
}
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Visible = Properties . Settings . Default . showInfo ;
if ( ! groupBoxInformationen . Visible )
2019-07-29 17:32:26 +02:00
{
2019-08-15 20:31:28 +02:00
groupBoxZiele . Location = new Point ( groupBoxZiele . Location . X , 12 ) ;
groupBoxZiele . Height = groupBoxZiele . Height + 87 ;
2019-07-29 17:32:26 +02:00
}
2019-03-22 23:53:20 +01:00
CheckSubfolders ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
if ( string . IsNullOrEmpty ( startupimage ) )
{
LoadPicture ( 0 ) ;
}
else
{
LoadPicture ( GetImageIndex ( Path . Combine ( startuppath , startupimage ) ) ) ;
}
ResetUndo ( ) ;
2019-07-28 10:22:02 +02:00
ToolTip t1 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t1 . SetToolTip ( buttonJumpBack , "Voriges Bild" ) ;
ToolTip t2 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t2 . SetToolTip ( buttonJumpForward , "Nächstes Bild" ) ;
ToolTip t3 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t3 . SetToolTip ( buttonUndo , "Aktion Rückgängig machen" ) ;
ToolTip t4 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t4 . SetToolTip ( buttonSettings , "Einstellungen öffnen" ) ;
ToolTip t5 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t5 . SetToolTip ( buttonQuellPfad , "Quellpfad festlegen" ) ;
ToolTip t6 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t6 . SetToolTip ( buttonInfo , "Informationen ein-/ausblenden" ) ;
2019-08-07 15:55:48 +02:00
ToolTip t7 = new ToolTip
{
AutoPopDelay = 5000 ,
InitialDelay = 1000 ,
ReshowDelay = 500
} ;
t7 . SetToolTip ( buttonLastImage , "Letztes Bild anzeigen" ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Startpfad auf letzten Pfad legen, wenn Bilder vorhanden sind, sonst auf Bild-Bibliothek, wenn da auch keine sind, dann den Applikationspfad
/// </summary>
private void SetDefaultPath ( )
{
string tmpPath = Application . StartupPath ;
if ( string . IsNullOrEmpty ( startuppath ) )
{
if ( ! string . IsNullOrEmpty ( Properties . Settings . Default . lastPath ) & & Directory . Exists ( Properties . Settings . Default . lastPath ) )
{
tmpPath = Properties . Settings . Default . lastPath ;
}
int picsHere = 0 ;
foreach ( string type in fileTypes )
{
var list = Directory . GetFiles ( tmpPath , "*." + type ) ;
if ( list . Length > 0 )
{
picsHere + = list . Length ;
}
}
string myPics = Environment . GetFolderPath ( Environment . SpecialFolder . MyPictures ) ;
if ( Directory . Exists ( myPics ) & & picsHere = = 0 )
{
tmpPath = myPics ;
}
}
else
{
tmpPath = startuppath ;
}
quellPath = tmpPath ;
labelQuellPath . Text = tmpPath ;
if ( ! string . IsNullOrEmpty ( Properties . Settings . Default . targetPath ) )
{
zielPath = Properties . Settings . Default . targetPath ;
labelZielPath . Text = Properties . Settings . Default . targetPath ;
}
}
/// <summary>
/// Wenn Subfolders vorhanden, Text ausblenden und für jeden Subfolder einen Button anlegen
/// </summary>
private void CheckSubfolders ( )
{
if ( ! threadIsRunning )
{
folderThread = new Thread ( new ThreadStart ( CheckSubfoldersThread ) )
{
IsBackground = true
} ;
folderThread . Start ( ) ;
}
}
private void CheckSubfoldersThread ( )
{
threadIsRunning = true ;
try
{
var folders = Directory . GetDirectories ( zielPath , "*" , System . IO . SearchOption . TopDirectoryOnly ) ;
DirectoryInfo di = new DirectoryInfo ( zielPath ) ;
int dircount = di . GetDirectories ( ) . Length ;
Invoke ( new dlgRefreshButtons ( RefreshButtons ) , dircount , folders ) ;
}
catch ( Exception )
{
}
finally
{
threadIsRunning = false ;
}
}
/// <summary>
/// Erstellt für jeden Subfolder einen Button zum verschieben
/// </summary>
/// <param name="dircount"></param>
/// <param name="folders"></param>
private void RefreshButtons ( int dircount , string [ ] folders )
{
RemoveButtons ( buttons ) ;
buttons . Clear ( ) ;
if ( dircount > 0 )
{
labelNoTargets . Visible = false ;
AddButtons ( folders ) ;
}
else
{
labelNoTargets . Visible = true ;
}
}
public delegate void dlgRefreshButtons ( int dircount , string [ ] folders ) ;
/// <summary>
/// Fügt Buttons aus array hinzu
/// </summary>
/// <param name="folders"></param>
private void AddButtons ( string [ ] folders , int top = 9 , int left = 9 )
{
Array . Sort ( folders ) ;
foreach ( string folder in folders )
{
2019-08-15 20:31:28 +02:00
if ( Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "$RECYCLE" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "System Volume Information" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "ImageSorter" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "Image Sorter" & & Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) ! = "AssocIcons" )
2019-03-22 23:53:20 +01:00
{
Button button = new Button
{
Left = left ,
Top = top
} ;
int count = 0 ;
foreach ( string type in fileTypes )
{
try
{
count + = Directory . GetFiles ( folder , "*." + type ) . Count ( ) ;
}
catch ( Exception )
{
}
}
button . Text = Path . GetFileNameWithoutExtension ( folder ) . ToString ( ) + " (" + count + ")" ;
button . Size = new Size ( 225 , 30 ) ;
button . Click + = new EventHandler ( MovePicture ) ;
2019-08-07 15:55:48 +02:00
System . Timers . Timer tx = new System . Timers . Timer ( 35 ) ;
tx . Elapsed + = new System . Timers . ElapsedEventHandler ( ( sender1 , e1 ) = > ButtonFade ( button , tx ) ) ;
button . Tag = tx ;
2019-03-22 23:53:20 +01:00
buttons . Add ( button ) ;
top + = button . Height + 2 ;
}
}
foreach ( Button button in this . buttons )
{
2019-08-15 20:31:28 +02:00
panelButtons . Controls . Add ( button ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Entfernt alle Buttons aus Liste
/// </summary>
/// <param name="list"></param>
private void RemoveButtons ( List < Button > list )
{
foreach ( Button button in list )
{
2019-08-15 20:31:28 +02:00
panelButtons . Controls . Remove ( button ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Einstellungen ändern
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSettings_Click ( object sender , EventArgs e )
{
Settings s = new Settings ( ) ;
s . ShowDialog ( ) ;
zielPath = Properties . Settings . Default . targetPath ;
2019-04-05 10:52:47 +02:00
labelZielPath . Text = zielPath ;
2019-03-22 23:53:20 +01:00
imageIndex = 0 ;
2019-04-05 10:52:47 +02:00
if ( Properties . Settings . Default . fileAssociation )
{
ExtractAssocIcons ( ) ;
2019-04-05 21:16:57 +02:00
FileAssociation . Add ( "Image_Sorter_JPG" , ".jpg" , Application . ExecutablePath , "JPG Bild" , $@"{Application.StartupPath}\AssocIcons\jpg.ico" ) ;
FileAssociation . Add ( "Image_Sorter_PNG" , ".png" , Application . ExecutablePath , "PNG Bild" , $@"{Application.StartupPath}\AssocIcons\png.ico" ) ;
FileAssociation . Add ( "Image_Sorter_GIF" , ".gif" , Application . ExecutablePath , "GIF Bild" , $@"{Application.StartupPath}\AssocIcons\gif.ico" ) ;
FileAssociation . Add ( "Image_Sorter_JPEG" , ".jpeg" , Application . ExecutablePath , "JPEG Bild" , $@"{Application.StartupPath}\AssocIcons\jpeg.ico" ) ;
FileAssociation . Add ( "Image_Sorter_BMP" , ".bmp" , Application . ExecutablePath , "BMP Bild" , $@"{Application.StartupPath}\AssocIcons\bmp.ico" ) ;
FileAssociation . Add ( "Image_Sorter_TIF" , ".tif" , Application . ExecutablePath , "TIF Bild" , $@"{Application.StartupPath}\AssocIcons\tif.ico" ) ;
FileAssociation . Add ( "Image_Sorter_TIFF" , ".tiff" , Application . ExecutablePath , "TIFF Bild" , $@"{Application.StartupPath}\AssocIcons\tiff.ico" ) ;
2019-04-05 10:52:47 +02:00
}
else
{
2019-08-07 15:55:48 +02:00
if ( Directory . Exists ( $@"{Application.StartupPath}\AssocIcons" ) )
{
Directory . Delete ( $@"{Application.StartupPath}\AssocIcons" , true ) ;
2019-12-27 14:59:29 +01:00
FileAssociation . Remove ( "Image_Sorter_JPG" ) ;
FileAssociation . Remove ( "Image_Sorter_PNG" ) ;
FileAssociation . Remove ( "Image_Sorter_GIF" ) ;
FileAssociation . Remove ( "Image_Sorter_JPEG" ) ;
FileAssociation . Remove ( "Image_Sorter_BMP" ) ;
FileAssociation . Remove ( "Image_Sorter_TIF" ) ;
FileAssociation . Remove ( "Image_Sorter_TIFF" ) ;
2019-08-07 15:55:48 +02:00
}
2019-04-05 10:52:47 +02:00
}
2019-03-22 23:53:20 +01:00
CheckSubfolders ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
ResetUndo ( ) ;
}
/// <summary>
/// Fügt alle Bilder des aktuellen Verzeichnisses der Liste hinzu
/// </summary>
private void SearchImages ( )
{
images . Clear ( ) ;
foreach ( string type in fileTypes )
{
var list = Directory . GetFiles ( quellPath , "*." + type ) . OrderBy ( d = > new FileInfo ( d ) . Name ) ;
foreach ( string image in list )
{
images . Add ( image ) ;
}
}
}
/// <summary>
/// Gibt den Index des Bildes in der Bilderliste zurück
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
private int GetImageIndex ( string image )
{
2020-03-22 10:18:02 +01:00
int index = images . IndexOf ( image ) ;
2019-03-22 23:53:20 +01:00
return index ;
}
/// <summary>
/// Zählt die Bilddateien im Pfad
/// </summary>
private void CountPicsInPath ( )
{
Thread thread = new Thread ( new ThreadStart ( CountPicsInPathThread ) )
{
IsBackground = true
} ;
thread . Start ( ) ;
}
private void CountPicsInPathThread ( )
{
Monitor . Enter ( locker ) ;
try
{
int counted = 0 ;
counted = images . Count ( ) ;
Invoke ( new dlgRefreshCounters ( RefreshCounters ) , counted ) ;
}
catch ( Exception )
{
}
finally
{
Monitor . Exit ( locker ) ;
}
}
public delegate void dlgRefreshCounters ( int counted ) ;
/// <summary>
/// aktualisiert die Zähler zur Bilderaktionsstatistik
/// </summary>
/// <param name="total"></param>
private void RefreshCounters ( int total )
{
if ( total = = 0 )
{
labelCounter . Text = "keine Bilder vorhanden" ;
SetButtonsEnabled ( false ) ;
}
else if ( total = = 1 )
{
labelCounter . Text = "1 Bild gesamt" ;
SetButtonsEnabled ( true ) ;
}
else
{
labelCounter . Text = total . ToString ( ) + " Bilder gesamt" ;
SetButtonsEnabled ( true ) ;
}
if ( moved = = 0 )
{
labelCounter . Text + = Environment . NewLine + "keines verschoben" ;
}
else
{
labelCounter . Text + = Environment . NewLine + this . moved . ToString ( ) + " bereits verschoben" ;
}
}
/// <summary>
/// Subdirectory-Ordner Buttons aktivieren/dekativieren
/// </summary>
/// <param name="enabled"></param>
private void SetButtonsEnabled ( bool enabled )
{
foreach ( Button b in buttons )
{
b . Enabled = enabled ;
}
buttonDeleteImage . Enabled = enabled ;
buttonMirrorHorizontal . Enabled = enabled ;
buttonMirrorVertikal . Enabled = enabled ;
buttonRotate180 . Enabled = enabled ;
buttonRotate270 . Enabled = enabled ;
buttonRotate90 . Enabled = enabled ;
2019-04-02 17:36:31 +02:00
comboBoxZoom . Enabled = enabled ;
2019-07-28 10:22:02 +02:00
buttonJumpForward . Enabled = enabled ;
2019-03-22 23:53:20 +01:00
labelNoImages . Visible = ! enabled ;
}
/// <summary>
/// Lädt das Bild in die Picturebox
/// </summary>
/// <param name="index"></param>
private void LoadPicture ( int index )
{
if ( images . Count ( ) > 0 )
{
imageIndex = index ;
if ( imageIndex > = images . Count ( ) | | imageIndex < 0 )
{
imageIndex = 0 ;
}
2019-08-15 20:31:28 +02:00
pictureBoxImage . ImageLocation = CropImageBorders ( images . ElementAt ( imageIndex ) ) ;
2020-01-19 08:40:43 +01:00
Text = defaultWindowName + " - " + Path . GetFileName ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Image = null ;
2020-01-19 08:40:43 +01:00
Text = defaultWindowName ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Entfernt gleichfarbige Rahmen automatisch von Bildern
/// </summary>
/// <param name="imagepath"></param>
private string CropImageBorders ( string imagepath )
{
try
{
Bitmap p = new Bitmap ( imagepath ) ;
Bitmap x = BorderCropper . CropUnwantedBackground ( p ) ;
p . Dispose ( ) ;
if ( x ! = null )
{
x . Save ( imagepath ) ;
Image myImg = CopyImage . GetCopyImage ( imagepath ) ;
ShowAutoBorderChopMessage ( myImg , imagepath ) ;
}
}
catch ( Exception )
{
}
return imagepath ;
}
/// <summary>
/// Löscht die Undo-History
/// </summary>
private void ResetUndo ( )
{
history . Clear ( ) ;
CheckUndo ( ) ;
}
/// <summary>
/// Prüft ob Undo möglich ist
/// </summary>
private void CheckUndo ( )
{
if ( history . Count ( ) > 0 )
{
buttonUndo . Enabled = true ;
}
else
{
buttonUndo . Enabled = false ;
}
}
/// <summary>
/// Verschiebt ein Bild in ein Unterverzeichnis
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MovePicture ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string [ ] folderButton = btn . Text . Split ( '(' ) ;
int count = int . Parse ( folderButton [ 1 ] . Substring ( 0 , folderButton [ 1 ] . Length - 1 ) ) + 1 ;
string targetPath = Path . Combine ( zielPath , folderButton [ 0 ] . Substring ( 0 , folderButton [ 0 ] . Length - 1 ) ) ;
try
{
2020-03-22 10:18:02 +01:00
string fullTargetPath = Path . Combine ( targetPath , CleanFileName ( Path . GetFileName ( pictureBoxImage . ImageLocation ) ) ) ;
2019-08-15 20:31:28 +02:00
Image myImg = CopyImage . GetCopyImage ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
if ( File . Exists ( fullTargetPath ) )
{
2020-03-22 10:18:02 +01:00
using ( var form = new Vergleicher ( "Das zu verschiebende Bild \"" + CleanFileName ( Path . GetFileName ( pictureBoxImage . ImageLocation ) ) + "\"" + "existiert im Zielverzeichnis \"" + btn . Text + "\" bereits." + Environment . NewLine + Environment . NewLine + "Soll eine Kopie angelegt werden? Nein überschreibt die Datei, Abbrechen bricht den Vorgang ab." , pictureBoxImage . ImageLocation , fullTargetPath ) )
2019-03-22 23:53:20 +01:00
{
var result = form . ShowDialog ( ) ;
if ( result = = DialogResult . Yes )
{
2020-03-22 10:18:02 +01:00
fullTargetPath = Path . Combine ( targetPath , CleanFileName ( Path . GetFileNameWithoutExtension ( pictureBoxImage . ImageLocation ) ) + Randomize . NumbersAndDigits ( 5 , "_" ) + Path . GetExtension ( pictureBoxImage . ImageLocation ) ) ;
2019-03-22 23:53:20 +01:00
}
else if ( result = = DialogResult . No )
{
2019-08-15 20:31:28 +02:00
File . Copy ( pictureBoxImage . ImageLocation , fullTargetPath , true ) ;
File . Delete ( pictureBoxImage . ImageLocation ) ;
images . Remove ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
history . Add ( fullTargetPath ) ;
moved + + ;
ShowMovedMessage ( myImg , fullTargetPath , btn . Text ) ;
CheckSubfolders ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
CheckUndo ( ) ;
return ;
}
else
{
return ;
}
}
}
2019-08-15 20:31:28 +02:00
File . Move ( pictureBoxImage . ImageLocation , fullTargetPath ) ;
images . Remove ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
history . Add ( fullTargetPath ) ;
moved + + ;
ShowMovedMessage ( myImg , fullTargetPath , btn . Text ) ;
}
catch ( IOException ex )
{
MessageBox . Show ( ex . ToString ( ) ) ;
}
btn . Text = folderButton [ 0 ] + "(" + count + ")" ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
CheckUndo ( ) ;
2019-08-07 15:55:48 +02:00
if ( Properties . Settings . Default . fading )
{
btn . BackColor = Color . LightSalmon ;
btn . ForeColor = Color . MediumSeaGreen ;
btn . Font = new Font ( btn . Font , FontStyle . Bold ) ;
System . Timers . Timer t = new System . Timers . Timer ( 700 ) ;
t . Elapsed + = new System . Timers . ElapsedEventHandler ( ( sender1 , e1 ) = > ButtonBlink ( sender , e , btn , t ) ) ;
t . Start ( ) ;
}
2019-07-29 17:32:26 +02:00
}
2020-03-22 10:18:02 +01:00
private string CleanFileName ( string filename )
{
string fn = filename ;
fn = fn . Replace ( "_crp" , "" ) ;
fn = fn . Replace ( "_cut" , "" ) ;
return fn ;
}
2019-07-29 17:32:26 +02:00
/// <summary>
/// Blinkender Button nach erfolgreichem Verschieben
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="btn"></param>
2019-08-07 15:55:48 +02:00
private void ButtonBlink ( object sender , EventArgs e , Button btn , System . Timers . Timer t )
2019-07-29 17:32:26 +02:00
{
btn . BeginInvoke ( new MethodInvoker ( ( ) = >
{
2019-08-07 15:55:48 +02:00
System . Timers . Timer tx = btn . Tag as System . Timers . Timer ;
if ( tx . Enabled )
{
tx . Stop ( ) ;
btn . BackColor = Color . LightSalmon ;
}
2019-07-29 17:32:26 +02:00
btn . ForeColor = SystemColors . ControlText ;
btn . Font = new Font ( btn . Font , FontStyle . Regular ) ;
2019-08-07 15:55:48 +02:00
tx . Start ( ) ;
2019-07-29 17:32:26 +02:00
} ) ) ;
t . Stop ( ) ;
2019-03-22 23:53:20 +01:00
}
2019-08-07 15:55:48 +02:00
/// <summary>
/// Hintergrundfarbe des Buttons langsam nach Transparent blenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="btn"></param>
private void ButtonFade ( Button btn , System . Timers . Timer tx )
{
btn . BeginInvoke ( new MethodInvoker ( ( ) = >
{
int speed = Properties . Settings . Default . fadingSpeed * ( Properties . Settings . Default . fadingSpeed / 3 ) + 1 ;
int alpha = btn . BackColor . A ;
if ( alpha - speed > = 0 )
{
btn . BackColor = Color . FromArgb ( btn . BackColor . A - speed , btn . BackColor . R , btn . BackColor . G , btn . BackColor . B ) ;
}
else
{
btn . BackColor = Color . Transparent ;
tx . Stop ( ) ;
}
} ) ) ;
}
2019-03-22 23:53:20 +01:00
/// <summary>
/// Macht die letzte Aktion rückgängig
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonUndo_Click ( object sender , EventArgs e )
{
string targetPath = Path . Combine ( this . quellPath , Path . GetFileName ( history . ElementAt ( history . Count ( ) - 1 ) ) ) ;
if ( Path . GetFullPath ( history . ElementAt ( history . Count ( ) - 1 ) ) . StartsWith ( "C:\\img-tmp" ) )
{
2019-08-15 20:31:28 +02:00
targetPath = pictureBoxImage . ImageLocation ;
2019-03-22 23:53:20 +01:00
}
try
{
Image myImg = CopyImage . GetCopyImage ( history . ElementAt ( history . Count ( ) - 1 ) ) ;
File . Copy ( history . ElementAt ( history . Count ( ) - 1 ) , targetPath , true ) ;
File . Delete ( history . ElementAt ( history . Count ( ) - 1 ) ) ;
history . Remove ( history . ElementAt ( history . Count ( ) - 1 ) ) ;
images . Insert ( imageIndex , targetPath ) ;
moved - - ;
ShowUndoMessage ( myImg , targetPath ) ;
}
catch ( IOException ex )
{
MessageBox . Show ( ex . ToString ( ) ) ;
}
CheckSubfolders ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
CheckUndo ( ) ;
}
/// <summary>
/// Dreht das Bild und überschreibt es
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImageRotate ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string rotateString = btn . Tag . ToString ( ) ;
int rotation = int . Parse ( rotateString ) ;
Image subject = Image . FromFile ( images . ElementAt ( imageIndex ) ) ;
if ( rotation = = 90 )
{
subject . RotateFlip ( RotateFlipType . Rotate90FlipNone ) ;
}
else if ( rotation = = 180 )
{
subject . RotateFlip ( RotateFlipType . Rotate180FlipNone ) ;
}
else
{
subject . RotateFlip ( RotateFlipType . Rotate270FlipNone ) ;
}
string ext = Path . GetExtension ( images . ElementAt ( imageIndex ) ) ;
if ( ext = = ".png" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Png ) ;
}
else if ( ext = = ".gif" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Gif ) ;
}
else
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Jpeg ) ;
}
LoadPicture ( imageIndex ) ;
2019-08-15 20:31:28 +02:00
groupBoxTransformation . Visible = false ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Spiegelt ein Bild und überschreibt es
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImageMirror ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string mirrorString = btn . Tag . ToString ( ) ;
Image subject = Image . FromFile ( images . ElementAt ( imageIndex ) ) ;
if ( mirrorString = = "x" )
{
subject . RotateFlip ( RotateFlipType . RotateNoneFlipX ) ;
}
else
{
subject . RotateFlip ( RotateFlipType . RotateNoneFlipY ) ;
}
string ext = Path . GetExtension ( images . ElementAt ( imageIndex ) ) ;
if ( ext = = ".png" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Png ) ;
}
else if ( ext = = ".gif" )
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Gif ) ;
}
else
{
subject . Save ( images . ElementAt ( imageIndex ) , ImageFormat . Jpeg ) ;
}
LoadPicture ( imageIndex ) ;
2019-08-15 20:31:28 +02:00
groupBoxTransformation . Visible = false ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Verschiebt ein Bild in den Papierkorb
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ImageDelete ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
Image myImg = CopyImage . GetCopyImage ( pictureBoxImage . ImageLocation ) ;
string pfad = Path . GetFileName ( pictureBoxImage . ImageLocation ) ;
FileSystem . DeleteFile ( pictureBoxImage . ImageLocation , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin , UICancelOption . DoNothing ) ;
images . Remove ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
CheckSubfolders ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( imageIndex ) ;
ShowDeletedMessage ( myImg , pfad ) ;
}
/// <summary>
2019-04-02 17:36:31 +02:00
/// Zoom-Optionen
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2019-04-02 17:36:31 +02:00
private void Zoom ( )
2019-03-22 23:53:20 +01:00
{
2019-04-02 17:36:31 +02:00
string zoom = comboBoxZoom . SelectedItem . ToString ( ) ;
2019-03-22 23:53:20 +01:00
2019-04-02 17:36:31 +02:00
if ( zoom = = "Original" )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . SizeMode = PictureBoxSizeMode . Zoom ;
pictureBoxImage . Size = new Size ( pictureBoxImage . Image . Width , pictureBoxImage . Image . Height ) ;
if ( pictureBoxImage . Image . Width > panelImageBackground . Width ) { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ; } else { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Image . Width / 2 ) ; }
if ( pictureBoxImage . Image . Height > panelImageBackground . Height ) { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ; } else { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Image . Height / 2 ) ; }
2019-03-22 23:53:20 +01:00
moveable = true ;
}
2019-04-02 17:36:31 +02:00
else if ( zoom = = "Vollbild" )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . SizeMode = PictureBoxSizeMode . Zoom ;
pictureBoxImage . Size = new Size ( panelImageBackground . Width , panelImageBackground . Height ) ;
pictureBoxImage . Top = 0 ;
pictureBoxImage . Left = 0 ;
2019-03-22 23:53:20 +01:00
moveable = false ;
}
2019-04-02 17:36:31 +02:00
else if ( zoom = = "Auto" )
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . SizeMode = PictureBoxSizeMode . Zoom ;
if ( pictureBoxImage . Image . Width > panelImageBackground . Width | | pictureBoxImage . Image . Height > panelImageBackground . Height )
2019-04-02 17:36:31 +02:00
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Size = new Size ( panelImageBackground . Width , panelImageBackground . Height ) ;
pictureBoxImage . Top = 0 ;
pictureBoxImage . Left = 0 ;
2019-04-02 17:36:31 +02:00
moveable = false ;
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Size = new Size ( pictureBoxImage . Image . Width , pictureBoxImage . Image . Height ) ;
if ( pictureBoxImage . Image . Width > panelImageBackground . Width ) { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ; } else { pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Image . Width / 2 ) ; }
if ( pictureBoxImage . Image . Height > panelImageBackground . Height ) { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ; } else { pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Image . Height / 2 ) ; }
2019-04-02 17:36:31 +02:00
moveable = true ;
}
}
2019-03-22 23:53:20 +01:00
else
{
return ;
}
2019-08-15 20:31:28 +02:00
xFaktor = pictureBoxImage . Width / ( double ) pictureBoxImage . Image . Width ;
yFaktor = pictureBoxImage . Height / ( double ) pictureBoxImage . Image . Height ;
labelZoom2 . Text = "x" + Math . Round ( yFaktor , 1 ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Mausklicks in picturebox verwalten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseDown ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Left )
{
if ( moveable )
{
moving = true ;
startLocation = e . Location ;
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = grabbingCursor ;
2019-03-22 23:53:20 +01:00
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = Cursors . No ;
2019-03-22 23:53:20 +01:00
}
}
if ( e . Button = = MouseButtons . Middle )
{
if ( moveable )
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ;
pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ;
2019-03-22 23:53:20 +01:00
}
else
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = Cursors . No ;
2019-03-22 23:53:20 +01:00
}
}
}
/// <summary>
/// Mausklicks in picturebox verwalten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseUp ( object sender , MouseEventArgs e )
{
if ( moveable & & moving )
{
moving = false ;
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Top > 0 ) { pictureBoxImage . Top = 0 ; }
if ( pictureBoxImage . Top < - pictureBoxImage . Height + panelImageBackground . Height ) { pictureBoxImage . Top = - pictureBoxImage . Height + panelImageBackground . Height ; }
if ( pictureBoxImage . Left > 0 ) { pictureBoxImage . Left = 0 ; }
if ( pictureBoxImage . Left < - pictureBoxImage . Width + panelImageBackground . Width ) { pictureBoxImage . Left = - pictureBoxImage . Width + panelImageBackground . Width ; }
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
pictureBoxImage . Cursor = grabCursor ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Bildausschnitt verschieben
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseMove ( object sender , MouseEventArgs e )
{
if ( moving )
{
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Top > 0 ) { pictureBoxImage . Top = 0 ; }
if ( pictureBoxImage . Top < - pictureBoxImage . Height + panelImageBackground . Height ) { pictureBoxImage . Top = - pictureBoxImage . Height + panelImageBackground . Height ; }
if ( pictureBoxImage . Left > 0 ) { pictureBoxImage . Left = 0 ; }
if ( pictureBoxImage . Left < - pictureBoxImage . Width + panelImageBackground . Width ) { pictureBoxImage . Left = - pictureBoxImage . Width + panelImageBackground . Width ; }
pictureBoxImage . Top + = e . Location . Y - startLocation . Y ;
pictureBoxImage . Left + = e . Location . X - startLocation . X ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Bild Zoom
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ZoomInOut ( object sender , MouseEventArgs e )
{
2019-08-15 20:31:28 +02:00
if ( e . Delta ! = 0 & & pictureBoxImage . Image ! = null )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
double xstep = pictureBoxImage . Width * 0.01 ;
double ystep = pictureBoxImage . Height * 0.01 ;
2019-03-22 23:53:20 +01:00
if ( xstep < 1.0 ) { xstep = 1.0 ; }
if ( ystep < 1.0 ) { ystep = 1.0 ; }
2019-08-15 20:31:28 +02:00
int maxWidth = pictureBoxImage . Image . Width * 8 ;
int minWidth = pictureBoxImage . Image . Width / 8 ;
2019-03-22 23:53:20 +01:00
2019-08-15 20:31:28 +02:00
int newWidth = pictureBoxImage . Width - ( pictureBoxImage . Width / ( int ) xstep * ( e . Delta / 120 ) ) ;
int newHeight = pictureBoxImage . Height - ( pictureBoxImage . Height / ( int ) xstep * ( e . Delta / 120 ) ) ;
2019-03-22 23:53:20 +01:00
if ( newWidth < = maxWidth & & newWidth > = minWidth )
{
2019-08-15 20:31:28 +02:00
pictureBoxImage . Width = newWidth ;
pictureBoxImage . Height = newHeight ;
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Width > panelImageBackground . Width | | pictureBoxImage . Height > panelImageBackground . Height )
2019-03-22 23:53:20 +01:00
{
moveable = true ;
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Right < panelImageBackground . Width ) { pictureBoxImage . Left + = - pictureBoxImage . Right + panelImageBackground . Width ; }
if ( pictureBoxImage . Bottom < panelImageBackground . Height ) { pictureBoxImage . Top + = - pictureBoxImage . Bottom + panelImageBackground . Height ; }
2019-03-22 23:53:20 +01:00
}
else
{
moveable = false ;
2019-08-15 20:31:28 +02:00
pictureBoxImage . Top = ( panelImageBackground . Height / 2 ) - ( pictureBoxImage . Height / 2 ) ;
pictureBoxImage . Left = ( panelImageBackground . Width / 2 ) - ( pictureBoxImage . Width / 2 ) ;
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
xFaktor = pictureBoxImage . Width / ( double ) pictureBoxImage . Image . Width ;
yFaktor = pictureBoxImage . Height / ( double ) pictureBoxImage . Image . Height ;
labelZoom2 . Text = "x" + Math . Round ( yFaktor , 1 ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
/// Focus auf Panel1 bei MouseEnter in Picturebox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseEnter ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
panelImageBackground . Focus ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Focus auf Buttons bei MouseLeave von Picturebox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_MouseLeave ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Focus ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Bild in picturebox vollständig geladen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBox_LoadCompleted ( object sender , AsyncCompletedEventArgs e )
{
2019-04-02 17:36:31 +02:00
Zoom ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
/// Maus-Fokus auf Panel2 bei MouseEnter
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Panel2_MouseEnter ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
panelButtons . Focus ( ) ;
2019-03-22 23:53:20 +01:00
}
/// <summary>
2019-12-26 20:59:23 +01:00
/// Öffnet im Explorer den Ordner des Bildes und legt den Fokus auf das aktuelle Bild, wenn es existiert
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemOpenExplorer_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
if ( File . Exists ( pictureBoxImage . ImageLocation ) )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
Process . Start ( "explorer.exe" , @"/select, " + pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
}
2019-08-15 20:31:28 +02:00
else if ( Directory . Exists ( Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) ) )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
Process . Start ( "explorer.exe" , Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) ) ;
2019-03-22 23:53:20 +01:00
}
}
/// <summary>
2019-12-26 20:59:23 +01:00
/// Zeigt Details (Eigenschaften) zum aktuellen Bild an
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemImageDetails_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
using ( Image img = Image . FromFile ( pictureBoxImage . ImageLocation ) )
2019-03-22 23:53:20 +01:00
{
2019-08-15 20:31:28 +02:00
FileInfo info = new FileInfo ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
ImageFormat format = img . RawFormat ;
MessageBox . Show ( "Dateiname: " + info . Name + Environment . NewLine +
"Pfad: " + info . DirectoryName + Environment . NewLine +
"Erstellt: " + info . CreationTime + Environment . NewLine +
"Geändert: " + info . LastWriteTime + Environment . NewLine +
"Bildformat: " + new ImageFormatConverter ( ) . ConvertToString ( format ) + Environment . NewLine +
"Abmessungen: " + img . Width + " x " + img . Height + Environment . NewLine +
"Breite: " + img . Width + " Px" + Environment . NewLine +
"Höhe: " + img . Height + " Px" + Environment . NewLine +
"Auflösung: " + Resolution . GetImageResolution ( img ) + Environment . NewLine +
"Größe: " + FileSize . GetFileSize ( info . Length ) + Environment . NewLine +
"Bittiefe: " + Image . GetPixelFormatSize ( img . PixelFormat ) + " bit" , "Bildeigenschaften" , MessageBoxButtons . OK ) ;
}
}
2019-12-26 20:59:23 +01:00
/// <summary>
/// Zeigt die EXIF-Daten vom aktuellen Bild an
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemShowEXIF_Click ( object sender , EventArgs e )
{
using ( Image img = Image . FromFile ( pictureBoxImage . ImageLocation ) )
{
EXIF exif = new EXIF ( img . PropertyItems ) ;
exif . ShowDialog ( ) ;
}
}
2019-03-22 23:53:20 +01:00
/// <summary>
/// Öffnet Paint zum Bearbeiten des Bildes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItemEditImage_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
FileInfo info = new FileInfo ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
ProcessStartInfo pi = new ProcessStartInfo
{
FileName = ( "mspaint.exe" ) ,
UseShellExecute = false ,
Arguments = "\"" + info . FullName + "\""
} ;
Process p = new Process
{
StartInfo = pi
} ;
p . Start ( ) ;
p . WaitForExit ( ) ;
LoadPicture ( imageIndex ) ;
}
/// <summary>
/// Öffnet das Cropping-Form um Bilder zuzuschneiden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BildZuschneidenToolStripMenuItem_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
Cropper cropper = new Cropper ( pictureBoxImage . ImageLocation ) ;
2019-03-22 23:53:20 +01:00
DialogResult result = cropper . ShowDialog ( this ) ;
if ( result = = DialogResult . OK )
{
2019-08-15 20:31:28 +02:00
string del = pictureBoxImage . ImageLocation ;
2019-03-22 23:53:20 +01:00
images [ imageIndex ] = cropper . NewFileLocation ;
LoadPicture ( imageIndex ) ;
FileSystem . DeleteFile ( del , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin , UICancelOption . DoNothing ) ;
}
}
/// <summary>
2019-12-26 20:59:23 +01:00
/// Größe, Position in Settings speichern vor dem Schließen
2019-03-22 23:53:20 +01:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_FormClosing ( object sender , FormClosingEventArgs e )
{
Properties . Settings . Default . lastPath = quellPath ;
Properties . Settings . Default . lastWidth = Width ;
Properties . Settings . Default . lastHeight = Height ;
Properties . Settings . Default . lastTop = Top ;
Properties . Settings . Default . lastLeft = Left ;
2019-08-15 20:31:28 +02:00
Properties . Settings . Default . showInfo = groupBoxInformationen . Visible ;
2020-01-10 21:27:04 +01:00
Properties . Settings . Default . fullScreen = ( WindowState = = FormWindowState . Maximized ? true : false ) ;
2019-03-22 23:53:20 +01:00
Properties . Settings . Default . Save ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei verschobenem Bild
/// </summary>
/// <param name="bildpfad"></param>
/// <param name="ordnername"></param>
private void ShowMovedMessage ( Image bild , string bildpfad , string ordnername )
{
banner . Enqueue ( "Bild \"" + Path . GetFileName ( bildpfad ) + "\" erfolgreich nach" , "\"" + ordnername + "\" verschoben." , bild , Properties . Resources . move ) ;
banner . ShowMessages ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei gelöschtem Bild
/// </summary>
/// <param name="bild"></param>
/// <param name="bildname"></param>
private void ShowDeletedMessage ( Image bild , string bildname )
{
banner . Enqueue ( "Bild \"" + bildname + "\" erfolgreich gelöscht." , "" , bild , Properties . Resources . delete ) ;
banner . ShowMessages ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei rückgängig gemachter Aktion
/// </summary>
/// <param name="bildpfad"></param>
private void ShowUndoMessage ( Image bild , string bildpfad )
{
banner . Enqueue ( "Bildaktion für \"" + Path . GetFileName ( bildpfad ) + "\" erfolgreich" , "rückgängig gemacht." , bild , Properties . Resources . undo ) ;
banner . ShowMessages ( ) ;
}
/// <summary>
/// Anzeige eines Banners bei automatischem zuschneiden der Ränder
/// </summary>
/// <param name="bildpfad"></param>
private void ShowAutoBorderChopMessage ( Image bild , string bildpfad )
{
banner . Enqueue ( "Die Ränder für \"" + Path . GetFileName ( bildpfad ) + "\" wurden" , "automatisch zugeschnitten." , bild , Properties . Resources . crop ) ;
banner . ShowMessages ( ) ;
}
2019-08-10 12:03:16 +02:00
/// <summary>
/// Anzeige eines Banners bei erstelltem Duplikat
/// </summary>
/// <param name="bild"></param>
/// <param name="bildpfad"></param>
private void ShowDuplicatedMessage ( Image bild , string bildpfad )
{
2019-08-15 20:31:28 +02:00
banner . Enqueue ( "Das Duplikat \"" + Path . GetFileName ( bildpfad ) + "\"" , "wurde erstellt." , bild , Properties . Resources . duplicate ) ;
2019-08-10 12:03:16 +02:00
banner . ShowMessages ( ) ;
}
2019-03-22 23:53:20 +01:00
/// <summary>
/// Bild wieder neu zentrieren und skalieren nach Größenänderung des Fensters
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2020-01-12 09:37:11 +01:00
private void Main_Resize ( object sender , EventArgs e )
2019-03-22 23:53:20 +01:00
{
2020-01-12 09:37:11 +01:00
if ( WindowState ! = FormWindowState . Minimized )
{
lastState = WindowState ;
}
2019-03-22 23:53:20 +01:00
try
{
2019-04-02 17:36:31 +02:00
Zoom ( ) ;
2019-03-22 23:53:20 +01:00
}
catch ( Exception )
{
}
}
/// <summary>
/// Globale Tasten-Events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . KeyCode = = Keys . Delete )
{
buttonDeleteImage . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . Left | | e . KeyCode = = Keys . Down )
{
CountPicsInPath ( ) ;
LoadPicture ( imageIndex - 1 ) ;
CheckUndo ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . Right | | e . KeyCode = = Keys . Up )
{
CountPicsInPath ( ) ;
LoadPicture ( imageIndex + 1 ) ;
CheckUndo ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F2 )
{
toolStripMenuItemCropImage . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F3 )
{
toolStripMenuItemEditImage . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F4 )
{
toolStripMenuItemOpenExplorer . PerformClick ( ) ;
e . Handled = true ;
}
if ( e . KeyCode = = Keys . F5 )
{
toolStripMenuItemImageDetails . PerformClick ( ) ;
e . Handled = true ;
}
2019-12-26 20:59:23 +01:00
if ( e . KeyCode = = Keys . F6 )
{
toolStripMenuItemShowEXIF . PerformClick ( ) ;
e . Handled = true ;
}
2019-03-22 23:53:20 +01:00
if ( e . KeyCode = = Keys . Back )
{
buttonUndo . PerformClick ( ) ;
e . Handled = true ;
}
}
/// <summary>
/// Quellpfad auswählen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonQuellPfad_Click ( object sender , EventArgs e )
{
DialogResult result = folderBrowserDialog . ShowDialog ( ) ;
if ( result = = DialogResult . OK )
{
quellPath = folderBrowserDialog . SelectedPath ;
labelQuellPath . Text = quellPath ;
}
CheckSubfolders ( ) ;
SearchImages ( ) ;
CountPicsInPath ( ) ;
LoadPicture ( 0 ) ;
ResetUndo ( ) ;
}
2019-04-02 17:36:31 +02:00
/// <summary>
/// Zoom-Combobox geändert
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxZoom_SelectedIndexChanged ( object sender , EventArgs e )
{
Properties . Settings . Default . zoom = comboBoxZoom . SelectedIndex ;
Properties . Settings . Default . Save ( ) ;
2019-08-15 20:31:28 +02:00
if ( pictureBoxImage . Image ! = null )
2019-04-02 17:36:31 +02:00
{
Zoom ( ) ;
}
}
2019-07-28 10:22:02 +02:00
/// <summary>
/// Zu vorherigem Bild springen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonJumpBack_Click ( object sender , MouseEventArgs e )
{
CountPicsInPath ( ) ;
2019-08-07 15:55:48 +02:00
LoadPicture ( imageIndex - 1 ) ;
2019-07-28 10:22:02 +02:00
CheckUndo ( ) ;
}
/// <summary>
/// Zu nächstem Bild springen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonJumpForward_Click ( object sender , MouseEventArgs e )
{
CountPicsInPath ( ) ;
LoadPicture ( imageIndex + 1 ) ;
CheckUndo ( ) ;
}
/// <summary>
/// Informationen ein-/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonInfo_Click ( object sender , EventArgs e )
{
2019-08-15 20:31:28 +02:00
if ( groupBoxInformationen . Visible )
2019-07-28 10:22:02 +02:00
{
//ausblenden
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Visible = false ;
groupBoxZiele . Location = new Point ( groupBoxZiele . Location . X , 12 ) ;
groupBoxZiele . Height = groupBoxZiele . Height + 87 ;
2019-07-28 10:22:02 +02:00
}
else
{
//einblenden
2019-08-15 20:31:28 +02:00
groupBoxInformationen . Visible = true ;
groupBoxZiele . Location = new Point ( groupBoxZiele . Location . X , 99 ) ;
groupBoxZiele . Height = groupBoxZiele . Height - 87 ;
2019-07-28 10:22:02 +02:00
}
}
2019-08-07 15:55:48 +02:00
2019-08-10 12:03:16 +02:00
/// <summary>
/// Blendet letztes Bild ein
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2019-08-07 15:55:48 +02:00
private void ButtonLastImage_MouseDown ( object sender , MouseEventArgs e )
{
//todo vorheriges Bild anzeigen
}
2019-08-10 12:03:16 +02:00
/// <summary>
/// Blendet letztes Bild aus
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2019-08-07 15:55:48 +02:00
private void ButtonLastImage_MouseUp ( object sender , MouseEventArgs e )
{
//todo vorheriges Bild ausblenden
}
2019-08-10 12:03:16 +02:00
/// <summary>
2019-08-15 20:31:28 +02:00
/// Duplikat von aktuellem Bild erzeugen
2019-08-10 12:03:16 +02:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDuplicate_Click ( object sender , EventArgs e )
{
//aktuelles bild kopieren
2019-12-26 20:59:23 +01:00
string targetPath = Path . Combine ( Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) , Path . GetFileNameWithoutExtension ( pictureBoxImage . ImageLocation ) + Randomize . NumbersAndDigits ( 5 , "_" ) + Path . GetExtension ( pictureBoxImage . ImageLocation ) ) ;
2019-08-15 20:31:28 +02:00
File . Copy ( pictureBoxImage . ImageLocation , targetPath , true ) ;
2019-08-10 12:03:16 +02:00
//duplikat als nächstes bild in liste aufnehmen
images . Insert ( imageIndex + 1 , targetPath ) ;
CountPicsInPath ( ) ;
//duplikat-message anzeigen
Image myImg = CopyImage . GetCopyImage ( targetPath ) ;
ShowDuplicatedMessage ( myImg , targetPath ) ;
}
2019-08-15 20:31:28 +02:00
/// <summary>
/// Untermenü für Transformation ein-/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonTransformation_Click ( object sender , EventArgs e )
{
groupBoxTransformation . Visible = ! groupBoxTransformation . Visible ;
}
/// <summary>
/// Hintergrund hell/dunkel schalten
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonHintergrund_Click ( object sender , EventArgs e )
{
if ( panelImageBackground . BackColor = = Color . Black )
{
panelImageBackground . BackColor = SystemColors . Control ;
pictureBoxImage . BackColor = SystemColors . Control ;
}
else
{
panelImageBackground . BackColor = Color . Black ;
pictureBoxImage . BackColor = Color . Black ;
}
}
/// <summary>
/// Ränder schneiden Untermenü ein-/ausblenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRander_Click ( object sender , EventArgs e )
{
groupBoxRander . Visible = ! groupBoxRander . Visible ;
}
/// <summary>
/// Rand von Bild schneiden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RandSchneiden_Click ( object sender , EventArgs e )
{
Button btn = ( Button ) sender ;
string cutString = btn . Tag . ToString ( ) ;
Image im = pictureBoxImage . Image ;
2019-08-16 21:27:34 +02:00
int move = trackBarRander . Value ;
2019-08-15 20:31:28 +02:00
int x = 0 , y = 0 , width = im . Width , height = im . Height ;
if ( cutString = = "links" )
{
x + = move ;
width - = move ;
}
else if ( cutString = = "rechts" )
{
width - = move ;
}
else if ( cutString = = "oben" )
{
y + = move ;
height - = move ;
}
else if ( cutString = = "unten" )
{
height - = move ;
}
Rectangle r = new Rectangle ( x , y , width , height ) ;
Image res = CropImage ( im , r ) ;
string folder = Path . GetDirectoryName ( pictureBoxImage . ImageLocation ) ;
string file = Path . GetFileNameWithoutExtension ( pictureBoxImage . ImageLocation ) + "_cut" ;
string ext = Path . GetExtension ( pictureBoxImage . ImageLocation ) ;
string newFileLocation = Path . Combine ( folder , file + ext ) ;
string del = pictureBoxImage . ImageLocation ;
if ( ext = = ".png" )
{
res . Save ( newFileLocation , ImageFormat . Png ) ;
}
else if ( ext = = ".gif" )
{
res . Save ( newFileLocation , ImageFormat . Gif ) ;
}
else
{
res . Save ( newFileLocation , ImageFormat . Jpeg ) ;
}
images [ imageIndex ] = newFileLocation ;
LoadPicture ( imageIndex ) ;
FileSystem . DeleteFile ( del , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin , UICancelOption . DoNothing ) ;
groupBoxRander . Visible = false ;
}
/// <summary>
/// schneidet Bilder aus
/// </summary>
/// <param name="img"></param>
/// <param name="cropArea"></param>
/// <returns></returns>
private static Image CropImage ( Image img , Rectangle cropArea )
{
Bitmap bmpImage = new Bitmap ( img ) ;
Bitmap bmpCrop = bmpImage . Clone ( cropArea ,
bmpImage . PixelFormat ) ;
return ( Image ) ( bmpCrop ) ;
}
2019-08-16 21:27:34 +02:00
/// <summary>
/// Ändert das Pixel-Label auf den aktuellen Wert
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TrackBarRander_Scroll ( object sender , EventArgs e )
{
labelRander . Text = trackBarRander . Value + " px." ;
}
2019-03-22 23:53:20 +01:00
}
}