Skip to main content
Interwork Corporation
IDR Solutions Product Support Portal
PDF開発用語集 モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動

画像をフィットするようにリサイズする

フィットするようにリサイズ

この機能は何をするのか?

フィットするようにリサイズする操作は、定義されたピクセル矩形にできるだけぴったり収まるように画像を拡大縮小します。アスペクト比は維持されるため、画像が引き伸ばされることはなく、最終的に指定された幅または高さのいずれかになります(画像のアスペクト比が指定された新しいサイズと同じでない限り、両方にはなりません)。

JavaでBufferedImageをリサイズする

ImageProcessingOperations operations = new ImageProcessingOperations();

// ここでscale、blurなど複数の操作をチェーンできます
operations.resizeToFit(100, 100); // アスペクト比を維持して100x100ピクセルのボックスに画像をフィットさせる
        
// BufferedImageに操作を適用する
BufferedImage modifiedImage = operations.apply(BufferedImage originalImage);

フィットするようにリサイズする操作のJavadocを見る

追加のコード例

以下のコード例を使用して、画像形式間で処理と変換を行います:

Fileを使用する場合

File inputFile = new File("path/to/file");
File outputFile = new File("path/to/output-resizedToFit-file");
JDeli.convert(inputFile, outputFile, operations);

InputStreamとOutputSteamを使用する場合

final InputStream inputStream = new FileInputStream(inputFile);
final OutputStream outputStream = new FileOutputStream(outputFile);
final String outputFormat = "format"; // 出力ファイルの形式 例: png, jpeg,...;
JDeli.convert(inputStream, outputStream, outputFormat, operations);

byte[]を使用する場合

byte[] inputData = Files.readAllBytes(Paths.get("/path/to/file"));
final String outputFormat = "format"; // 出力ファイルの形式 例: png, jpeg,...;
byte[] outputData = JDeli.convert(inputData, outputFormat, operations);