検索
ホームページJava&#&チュートリアル大きな画像を大幅に縮小する場合、画質を維持するにはどうすればよいですか?

How can I preserve image quality when downsizing large images significantly?

品質を維持しながら大規模な画像のダウンサイズを行う

画像を過度にダウンサイズすると、品質に問題が生じる可能性があります。これに対処するには、分割統治が効果的な方法です。方法は次のとおりです:

1.元の画像:

大きな画像を大幅に縮小する場合、画質を維持するにはどうすればよいですか?

2.増分ダウンサイズ:

1 ステップで 300x300 から 60x60 にサイズ変更するのではなく、段階的にスケールします:

  1. 150x150 (元の寸法の 1/2) にサイズ変更します
  2. 75x75 (1/2) にサイズ変更します。 150x150)
  3. 37x38 (75x75 の 1/2) にサイズ変更します
  4. 60x60 (37x38 の 1/2) にサイズ変更します

各ステップで画像の寸法が次のように縮小されます。半分。

3.結果:

ここに画像の説明を入力してください

4.比較 (One Step と Divide and Conquer):

ここに画像の説明を入力してください

5. Java 実装:
public class DivideAndConquerImageResizer {

    public static main(String[] args) {
        // Load the original image
        BufferedImage original = ImageIO.read(...);

        // Create a scaled image
        BufferedImage scaled = null;

        Dimension currentSize = new Dimension(original.getWidth(), original.getHeight());
        Dimension desiredSize = new Dimension(60, 60);

        while (currentSize.getWidth() > desiredSize.getWidth()
               || currentSize.getHeight() > desiredSize.getHeight()) {
            // Halve the current size
            currentSize.width = (int) Math.ceil(currentSize.width / 2.0);
            currentSize.height = (int) Math.ceil(currentSize.height / 2.0);

            // Resize the image to the current size
            scaled = getScaledInstanceToFit(original, currentSize);
        }

        // Save the scaled image
        ImageIO.write(scaled, "jpg", ...);
    }

    public static BufferedImage getScaledInstanceToFit(BufferedImage img, Dimension size) {
        float scaleFactor = getScaleFactorToFit(img, size);
        return getScaledInstance(img, scaleFactor);
    }

    public static float getScaleFactorToFit(BufferedImage img, Dimension size) {
        float scale = 1f;
        if (img != null) {
            int imageWidth = img.getWidth();
            int imageHeight = img.getHeight();
            scale = getScaleFactorToFit(new Dimension(imageWidth, imageHeight), size);
        }
        return scale;
    }

    public static float getScaleFactorToFit(Dimension original, Dimension toFit) {
        float scale = 1f;
        if (original != null && toFit != null) {
            float dScaleWidth = getScaleFactor(original.width, toFit.width);
            float dScaleHeight = getScaleFactor(original.height, toFit.height);
            scale = Math.min(dScaleHeight, dScaleWidth);
        }
        return scale;
    }

    public static float getScaleFactor(int iMasterSize, int iTargetSize) {
        float scale = 1;
        if (iMasterSize > iTargetSize) {
            scale = (float) iTargetSize / (float) iMasterSize;
        } else {
            scale = (float) iTargetSize / (float) iMasterSize;
        }
        return scale;
    }

    public static BufferedImage getScaledInstance(BufferedImage img, double dScaleFactor) {
        BufferedImage imgBuffer = null;
        imgBuffer = getScaledInstance(img, dScaleFactor, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
        return imgBuffer;
    }

}

このアプローチにより、特にサイズを大幅にダウンした場合に、画質が著しく向上します。

以上が大きな画像を大幅に縮小する場合、画質を維持するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

mPDF

mPDF

mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。