0

私がやろうとしているのは、キーボードから「a」などの文字を受け取り、その文字を水平方向に反転して印刷することです。反転した画像をどこでも検索しましたが、それを行う方法はないようです。誰でも私を助けることができますか?私はこれをJavaでやろうとしています。詳細が必要な場合は、コメント セクションでお問い合わせください。

psオンラインで反転された文字が見つからなかったため、目的の出力を表示できません。画像の左右反転とコンセプトは同じですが、キャラでやってみたいです。

4

3 に答える 3

4

BufferedImageを作成し、それを取得しGraphics2Dてに設定してAffineTransformからAffineTransform.scale(-1, 1)、のメソッドを使用するなどGraphics2Dの方法を試すことができdrawStringます。それをコンソールに印刷することはできません-コンソールに印刷することで、あなたが提案していることはまったく可能ではないと思います-しかし、そのテクニックはあなたのために画像を生成します。

于 2012-01-30T19:16:13.340 に答える
1

画像を使用した実装; 文字自体を反転する方法があるかどうかはわかりません。

import java.io.*;

public class RotateAndFlip {


    static JPEGImage rotate90(JPEGImage inputImage) {
    JPEGImage outputImage = new JPEGImage(inputImage.getHeight(),
                          inputImage.getWidth());

    // Code to make outputImage into an image that is a 
    // 90 degree rotation of inputImage

    return outputImage;
    }
    static JPEGImage rotate180(JPEGImage inputImage) {
    return rotate90(rotate90(inputImage));
    }

    static JPEGImage rotate270(JPEGImage inputImage) {
    return rotate90(rotate90(rotate90(inputImage)));
    }

    static JPEGImage flipHorizontal(JPEGImage inputImage) {
    JPEGImage outputImage = new JPEGImage(inputImage.getWidth(),
                          inputImage.getHeight());

    // Code to make outputImage into an image that is a 
    // horizontal flip of inputImage

    return outputImage;
    }

    static JPEGImage flipVertical(JPEGImage inputImage) {
    return rotate90(flipHorizontal(rotate270(inputImage)));
    }

    public static void main (String args[]) {
    /* Check that the user has provided the right number of arguments */
    if (args.length != 1) {
        System.out.println("Usage: java JPEGCopy <source JPEG file> " + 
                   "<target JPEG file>");
        System.exit(1);
    }

    /* Create an empty image. We will read an image from a file into
       this object */
    JPEGImage imageOne = new JPEGImage();

    /* Try to open the file. This may cause an exception if the name 
       given is not a valid JPEG file so we need to catch the exceptions */
    try {
        imageOne.read(args[0]);
    } catch (Exception e) {
        /* An exception has been thrown. This is usually because the file
           either does not exist, or is not a JPEG image */
        System.out.println("Error reading file " + args[0]);
        System.out.println(e.getMessage());
        System.exit(1);
    }

    /* Make a new image to store the results in */
    JPEGImage imageTwo = new JPEGImage();


    /* Rotate by 90 degrees and write to a file */
    imageTwo = rotate90(imageOne);
    try {
        imageTwo.write("rotate90.jpg");
    } catch (Exception e) {
        System.out.println("Error writing file rotate90.jpg");
        System.out.println(e.getMessage());
        System.exit(1);
    }

    /* Rotate by 180 degrees and write to a file */
    imageTwo = rotate180(imageOne);
    try {
        imageTwo.write("rotate180.jpg");
    } catch (Exception e) {
        System.out.println("Error writing file rotate180.jpg");
        System.out.println(e.getMessage());
        System.exit(1);
    }

    /* Rotate by -90 degrees and write to a file */
    imageTwo = rotate270(imageOne);
    try {
        imageTwo.write("rotate270.jpg");
    } catch (Exception e) {
        System.out.println("Error writing file rotate270.jpg");
        System.out.println(e.getMessage());
        System.exit(1);
    }

    /* Flip horizontally and write to a file */
    imageTwo = flipHorizontal(imageOne);
    try {
        imageTwo.write("flipHorizontal.jpg");
    } catch (Exception e) {
        System.out.println("Error writing file flipHorizontal.jpg");
        System.out.println(e.getMessage());
        System.exit(1);
    }

    /* Flip vertically and write to a file */
    imageTwo = flipVertical(imageOne);
    try {
        imageTwo.write("flipVertical.jpg");
    } catch (Exception e) {
        System.out.println("Error writing file flipVertical.jpg");
        System.out.println(e.getMessage());
        System.exit(1);
    }

    }
}

ここ: http://www.cs.nott.ac.uk/~smx/IVIPracticals/exercise1.html

于 2012-01-30T19:30:05.530 に答える
0

何を達成しようとしているのかわからない。これを行う最も簡単な方法は、すべての文字と記号の画像のセットを取得し、従来のグラフィックソフトウェア(PaintShopPro、PhotoShopなど)を使用してそれらを反転することです。画像を個別のGIFの束として保存するか、 PNGファイルを作成し、必要なときに適切なファイルを取得します。

本当にJavaプログラム内でフリッピングを実行したい場合、重要なのは次のことだと思います。

  1. BufferedImageオブジェクトを作成します

  2. その上でcreateGraphicsを呼び出して、Graphicsオブジェクトを取得します。

  3. drawStringを使用して、このGraphicsオブジェクトに1つまたは複数の文字を書き込みます

  4. 次に、getRGBとsetRGBを使用して、画像を好きなように操作できます。基本的には、画像を上から中央に移動し、上半分から下半分にピクセルを入れ替えます。

任意のフォント、さまざまなサイズなどで機能させたい場合は、プログラムで実行する必要があると思います。

アップデート

1月30日のコメントに基づくと、反転画像を自分で生成するのではなく、Unicode文字セットから反転画像を見つけたいという意味のようです。私の知る限り、Unicodeにはすべての文字の反転画像が含まれているわけではありません。それ自体がシンボルであり、特定の意味を持ついくつかが含まれています。たとえば、UnicodeのU + 2203には後方大文字Eがありますが、Unicodeコードポイントが近くにある他の文字を見ると、それらがさまざまな数学記号であることがわかります。Unicodeの発明者がすべての文字の鏡像を提供しているためではなく、「存在する」を意味する数学記号であるため、後方Eは「そこに」あります。

私は確かに完全なUnicodeコードセットを記憶していないので、どこかにそのような文字のセットがないことを誓うことはできませんが、私は本当にそれを疑っています。Unicodeのポイントは、世界中のすべてのアルファベットと、一般的に使用される強力な記号のセットを表す方法を提供することであると考えられていました。斜体や太字など、またはサイズが異なる場合は、Unicodeコードポイントの異なるセットではなく、異なるフォントを選択して処理する必要があるため、意図的に個別のコードポイントを含めませんでした。したがって、すべてのシンボルの鏡像を追加した場合、非常に驚​​くでしょう。それはUnicodeの哲学に反するでしょう。そして、彼らがそれをしたのなら、なぜ逆さまのバージョンではないのですか?90度回転してみませんか?等

ですから、あなたの質問に対する簡単な答えは、それはできないということだと思います。そのようなUnicode文字はありません。

于 2012-01-30T19:17:30.437 に答える