// ================================================== // 画像ファイル1個を読み込み、拡大縮小して保存する関数 // ================================================== void processFile(string inputFilePath, string outputFilePath) { // 画像ファイルを開き、その内容を保持するグラフィックスリソースを生成 int inputGraphics = newGraphics(inputFilePath); // 高さを縦横比から自動設定するモードの場合は、高さを求めて outputHeight に代入(画像毎に変わる) if (heightMode == HEIGHT_MODE_AUTO) { // 元の画像の幅と高さを取得 int inputWidth = getGraphicsWidth(inputGraphics); int inputHeight = getGraphicsHeight(inputGraphics); // 指定された拡大・縮小後の幅を、元の画像の幅で割って拡大率を求める float magnification = (float)outputWidth / (float)inputWidth; // 元の画像の高さに拡大率をかけて、縦横比が保たれる拡大・縮小後の高さを求める outputHeight = (int)(inputHeight * magnification); // 注:グローバル変数に代入している } // inputGraphicsを拡大・縮小した、新しいグラフィックスデータを生成 int outputGraphics = newGraphics(inputGraphics, outputWidth, outputHeight, true); // trueは滑らかにするための指定 // 別のファイル名をつけて保存 exportGraphics(outputGraphics, outputFilePath, saveFormat, quality); // リソースを破棄 deleteGraphics(inputGraphics); deleteGraphics(outputGraphics); }