画像ビュア(PNG, JPEG 限定版)
■使い方
実行後、フォームに .PNG または .JPG のファイルをドラッグ&ドロップし、[←]または[→]を押下すると前後の画像を表示する。
画像は等倍で表示し、スクロールもしません。
■コマンドプロンプトから実行
PowerShell -NoProfile -ExecutionPolicy Unrestricted -File <.PS1> > nul
■コード(.PS1)
$s = '
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
public class GVCS : Form
{
const string STRAPP_TITLE = "GVCS";
Bitmap m_bmp;
List<string> m_listFile = new List<string>( 50 );
int m_nFileIndex = -1;
public GVCS()
{
// InitializeComponent();
this.AllowDrop = true;
this.ShowInTaskbar = true;
this.Text = STRAPP_TITLE;
this.DragEnter += GVCS_DragEnter;
this.DragDrop += GVCS_DragDrop;
this.Paint += GVCS_Paint;
this.KeyDown += GVCS_KeyDown;
}
private void GVCS_KeyDown( object sender, KeyEventArgs e )
{
switch( e.KeyCode )
{
case Keys.Escape:
Close();
break;
case Keys.Left:
if( m_listFile.Count > 1 )
{
if( m_nFileIndex > 0 )
{
m_nFileIndex --;
}
else
{
m_nFileIndex = m_listFile.Count - 1;
}
}
m_bmp = new Bitmap( m_listFile[m_nFileIndex] );
PaintForm();
break;
case Keys.Right:
if( m_listFile.Count > 1 )
{
if( m_nFileIndex < m_listFile.Count - 1 )
{
m_nFileIndex ++;
}
else
{
m_nFileIndex = 0;
}
m_bmp = new Bitmap( m_listFile[m_nFileIndex] );
PaintForm();
}
break;
}
}
private void GVCS_Paint( object sender, PaintEventArgs e)
{
if( m_bmp != null )
{
DrawImage();
}
}
private void GVCS_DragDrop( object sender, DragEventArgs e )
{
if( !e.Data.GetDataPresent(DataFormats.FileDrop) )
{
return;
}
string[] strFiles = (string[])e.Data.GetData( DataFormats.FileDrop );
int nImageIndex;
int nImageCounter = IsDropImage( out nImageIndex, strFiles );
if( nImageCounter > 0 )
{
if( nImageCounter == 1 )
{
m_nFileIndex = RegisteImage( strFiles[nImageIndex].ToLower() );
}
else
{
RegisteImage( strFiles );
}
if( m_bmp != null )
{
m_bmp.Dispose();
}
m_bmp = new Bitmap( m_listFile[m_nFileIndex] );
PaintForm();
}
}
private void GVCS_DragEnter( object sender, DragEventArgs e )
{
if( !e.Data.GetDataPresent(DataFormats.FileDrop) )
{
return;
}
e.Effect = DragDropEffects.Move;
}
private void PaintForm()
{
this.Text = string.Format(
@"{0:D4} / {1:D4} {2} - {3}",
m_nFileIndex + 1,
m_listFile.Count,
Path.GetFileName(m_listFile[m_nFileIndex]),
STRAPP_TITLE );
DrawImage();
}
private int RegisteImage( string strFile )
{
string strDirectory = System.IO.Path.GetDirectoryName( strFile );
string[] strFiles = System.IO.Directory.GetFiles( strDirectory, "*.*" );
RegisteImage( strFiles );
return m_listFile.FindIndex( (string strSearchFile) =>
{
return strSearchFile == strFile;
} );
}
private void RegisteImage( string[] strFiles )
{
m_listFile.Clear();
m_nFileIndex = 0;
for( int i = 0; i < strFiles.Length; i ++ )
{
string str = strFiles[i].ToLower();
strFiles[i] = str;
if( str.EndsWith(".png") ||
str.EndsWith(".jpg") )
{
m_listFile.Add( str );
}
}
m_listFile.Sort();
}
private int IsDropImage( out int nFileIndex, string[] strFiles )
{
int nCounter = 0;
nFileIndex = -1;
for( int i = 0; i < strFiles.Length; i ++ )
{
string str = strFiles[i].ToLower();
strFiles[i] = str;
if( strFiles[i].EndsWith(".png") ||
strFiles[i].EndsWith(".jpg") )
{
nCounter ++;
if( nFileIndex < 0 )
{
nFileIndex = i;
}
}
}
return nCounter;
}
private void DrawImage()
{
using( Graphics g = this.CreateGraphics() )
{
Brush brush = new SolidBrush( new Color() );
}
}
}
'
Add-Type $s -ReferencedAssemblies System.Windows.Forms,System.Drawing
$gv = [GVCS]::new()
$gv.ShowDialog()
■修正履歴
RegisteImage, IsDropImage を修正。2019-07-13
表示した画像がオープンしたままになっていた不具合を修正。
画像を切り替えるボタンを[←][→]に変更。2019-08-25