Example #1
0
        public static bool write( BufferedImage im, string formatName, File output )
        {
            System.Drawing.Imaging.ImageFormat fmt = System.Drawing.Imaging.ImageFormat.Bmp;
            switch ( formatName ) {
                case "BMP":
                case "bmp":
                fmt = System.Drawing.Imaging.ImageFormat.Bmp;
                break;
                case "jpg":
                case "JPG":
                case "jpeg":
                case "JPEG":
                fmt = System.Drawing.Imaging.ImageFormat.Jpeg;
                break;
                case "png":
                case "PNG":
                fmt = System.Drawing.Imaging.ImageFormat.Png;
                break;
                case "GIF":
                case "gif":
                fmt = System.Drawing.Imaging.ImageFormat.Gif;
                break;
                default:
                return false;
            }
            System.IO.FileStream fs = null;
            bool ret = false;
            try {
#if DEBUG
                sout.println( "ImageIO#write; output.getPath()=" + output.getPath() );
#endif
                fs = new System.IO.FileStream( output.getPath(), System.IO.FileMode.Create, System.IO.FileAccess.Write );
                im.image.Save( fs, fmt );
                ret = true;
            } catch ( System.Exception ex ) {
                ret = false;
                Logger.write( typeof( ImageIO ) + ".write; ex=" + ex );
                sout.println( typeof( ImageIO ) + "#write; ex=" + ex );
            } finally {
                if ( fs != null ) {
                    try {
                        fs.Close();
                    } catch { }
                }
            }
            return ret;
        }
Example #2
0
 /// <summary>
 /// この抽象パス名が示すファイルの名前を変更します。
 /// </summary>
 public bool renameTo( File dest )
 {
     try {
         System.IO.File.Replace( m_path, dest.m_path, m_path + "BAK" );
         return true;
     } catch {
     }
     return false;
 }
Example #3
0
 /// <summary>
 /// この抽象パス名が示すディレクトリにあるファイルおよびディレクトリの中で、指定されたフィルタの基準を満たすものの抽象パス名の配列を返します。
 /// </summary>
 public File[] listFiles( FilenameFilter filter )
 {
     List<File> ret = new List<File>();
     foreach ( string s in list() ) {
         if ( filter.accept( this, s ) ) {
             File f = new File( m_path + separator + s );
             ret.Add( f );
         }
     }
     return ret.ToArray();
 }
Example #4
0
 /// <summary>
 /// この抽象パス名が示すディレクトリ内のファイルを示す抽象パス名の配列を返します。
 /// </summary>
 public File[] listFiles()
 {
     string[] files = System.IO.Directory.GetFiles( m_path );
     File[] ret = new File[files.Length];
     for ( int i = 0; i < files.Length; i++ ) {
         ret[i] = new File( m_path + separator + files[i] );
     }
     return ret;
 }
Example #5
0
 /// <summary>
 /// 指定されたディレクトリで新しい空のファイルを生成し、その名前には、指定された接頭辞および接尾辞の文字列が使用されます。
 /// </summary>
 public static File createTempFile( string prefix, string suffix, File directory )
 {
     String dir = System.IO.Path.GetTempPath();
     if ( directory != null ) {
         dir = directory.m_path;
     }
     if ( !System.IO.Directory.Exists( dir ) ) {
         throw new System.IO.IOException();
     }
     while ( true ) {
         String f = prefix + System.IO.Path.GetRandomFileName() + suffix;
         String full = System.IO.Path.Combine( dir, f );
         if ( !System.IO.File.Exists( full ) ) {
             System.IO.File.Create( full );
             return new File( full );
         }
     }
     throw new System.IO.IOException();
 }
Example #6
0
 /// <summary>
 /// 2 つの抽象パス名を語彙的に比較します。
 /// </summary>
 public int compareTo( File pathname )
 {
     return System.IO.Path.GetFullPath( this.m_path ).CompareTo( System.IO.Path.GetFullPath( pathname.m_path ) );
 }