coding Shift_JIS; // 文字コードの明示(文字化け予防) import Graphics; // 画像処理に必要なライブラリの読み込み import File; // ファイルやフォルダの情報を扱うライブラリの読み込み import Text; // 文字列の操作や判定などに必要なライブラリの読み込み // 入出力フォルダのパスのデフォルト値 const string DEFAULT_INPUT_DIRECTORY = "./input"; const string DEFAULT_OUTPUT_DIRECTORY = "./output"; // 透明化したい色のRGB値をユーザーに入力してもらう(タイミングはmain関数実行よりも前) int fromRed = input("透明化する色の赤成分 ( 0〜255 ) は?", "0"); // 赤成分 int fromGreen = input("透明化する色の緑成分 ( 0〜255 ) は?", "255"); // 青成分 int fromBlue = input("透明化する色の青成分 ( 0〜255 ) は?", "0"); // 緑成分 int fromAlpha = 255; // 透明化したい元の色の不透明度(0で完全な透明、255で完全な不透明) // 変換後の色(透明以外の色にしたい場合はここを書き換える) int toRed = 0; // 赤成分 int toGreen = 0; // 青成分 int toBlue = 0; // 緑成分 int toAlpha = 0; // 不透明度(0で完全な透明、255で完全な不透明) // ================================================== // 全体的な処理 - この関数は起動時に自動で実行されます // ================================================== void main () { // 入出力フォルダのフルパスを用意 string inputDirectoryPath = getFilePath(DEFAULT_INPUT_DIRECTORY); string outputDirectoryPath = getFilePath(DEFAULT_OUTPUT_DIRECTORY); // 入出力フォルダをデフォルトから変更するかユーザーに尋ね、必要なら変更 if (confirm("入力先/出力先フォルダを指定しますか?(「いいえ」でデフォルトの場所使用)")) { inputDirectoryPath = choose("入力先フォルダを選択", "."); outputDirectoryPath = choose("出力先フォルダを選択", "."); } // 入力先フォルダ内の全ファイルを処理し、出力先フォルダに保存 processAllFiles(inputDirectoryPath, outputDirectoryPath); // 完了メッセージをユーザーに表示 pop("完了しました。画面上のファイル一覧を確認の上、ウィンドウを閉じてください。"); } // ================================================== // フォルダ内の全ファイルを走査して処理する関数 // ================================================== void processAllFiles(string inputDirectoryPath, string outputDirectoryPath) { // 入力フォルダ内にあるファイル名の一覧とファイル個数を取得 string fileNames[] = listDirectory(inputDirectoryPath); int fileN = length(fileNames); // 入力フォルダ内にある個々のファイルについて処理 for (int i=0; i OUTPUT: " + outputFilePath); // 色の透明化処理を実行 processFile(inputFilePath, outputFilePath); } } } // ================================================== // 画像ファイル1個を読み込み、透過処理して保存する関数 // ================================================== void processFile(string inputFilePath, string outputFilePath) { // 画像ファイルのパスからグラフィックスデータを生成 int inputGraphics = newGraphics(inputFilePath); // 色を変換したグラフィックスデータを生成 int outputGraphics = newGraphics( inputGraphics, // 元の画像を保持するグラフィックスデータ fromRed, fromGreen, fromBlue, fromAlpha, // 変換したい色(ユーザーが選んだ色) toRed, toGreen, toBlue, toAlpha // 変換後の色(透明) ); // 別のファイル名をつけて保存 exportGraphics(outputGraphics, outputFilePath, "PNG"); // PNG形式のファイルとして保存 // リソースを破棄 deleteGraphics(inputGraphics); deleteGraphics(outputGraphics); }