水平翻转字符并用java打印
我想做的是从键盘接收一个字符,例如“a”,然后水平翻转该字母并将其打印出来。我到处搜索翻转图像,但似乎没有任何方法可以做到这一点。有人可以帮助我吗?顺便说一句,我正在尝试用 Java 来做到这一点。 非常感谢,如果您需要更多详细信息,请在评论部分询问我。
ps 我无法向您显示所需的输出,因为我在网上找不到任何翻转的字符。 这个概念与图像水平翻转相同,但我想对字符执行此操作。
What I'm trying to do is receive a character from the keyboard, for example 'a' and flip that letter horizontally and print it out. I have searched everywhere for flipped images but there doesn't seem to exist any method to do that. Can anyone help me? I'm trying to do this in Java btw.
Thanks a lot in advance, if you need more details ask me in the comment section.
p.s. I can't show you the desired output because I couldn't find any flipped characters online.
The concept is the same as with an image horizontal flip, but I want to do this with characters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试创建
BufferedImage
、获取其Graphics2D
并将其AffineTransform
设置为AffineTransform.scale(-1, 1)
,然后使用Graphics2D
的drawString
方法。你将无法将其打印到控制台 - 我认为你所建议的打印到控制台根本不可能 - 但该技术将为你生成图像。You might try something like creating a
BufferedImage
, getting itsGraphics2D
and setting itsAffineTransform
toAffineTransform.scale(-1, 1)
, and then using theGraphics2D
'sdrawString
method. You're not going to be able to print that to the console -- I don't think what you're suggesting is possible at all, printing to the console -- but that technique would produce an image for you.使用图像实现;不确定是否有办法翻转角色本身。
这里:http://www.cs.nott.ac.uk/ ~smx/IVIPracticals/exercise1.html
Implementation using images; not sure if there's a way to flip the characters themselves.
Here: http://www.cs.nott.ac.uk/~smx/IVIPracticals/exercise1.html
不确定你想要实现什么目标。我认为最简单的方法是获取一组所有字母和符号的图像,使用任何传统的图形软件(PaintShopPro、PhotoShop 等)翻转它们,将图像保存为一堆单独的 GIF 或PNG 文件,然后在需要时检索适当的文件。
如果你真的想在Java程序中进行翻转,我认为关键是:
创建一个BufferedImage对象
对其调用createGraphics以获取一个Graphics对象。
p>
使用drawString 将一个或多个字符写入此Graphics 对象
然后您可以使用getRGB 和setRGB 来操纵图像。基本上,您希望从上到中心遍历图像,从上半部分到下半部分交换像素。
我想如果你想让它适用于任何字体、多种尺寸等,你就必须在程序中完成。
更新
根据您1月30日的评论,看来您的意思是您不想自己生成反转图像,而是想在Unicode字符集中找到反转图像。据我所知,恐怕 Unicode 并不包含每个字符的反转图像。它包括一些本身就是符号并且具有特定含义的符号。例如,Unicode 在 U+2203 处有一个向后大写的 E,但如果您查看具有附近 Unicode 代码点的其他字符,您会发现它们是各种数学符号。倒着的 E 表示“在那里”,因为它是一个数学符号,意思是“存在”,而不是因为 Unicode 的发明者给出了每个字符的镜像。
我当然没有记住完整的 Unicode 代码集,所以我不能发誓某处不存在这样的字符集,但我真的很怀疑。 Unicode 的目的应该是提供一种表示世界上所有字母的方法以及一组强大的常用符号。他们非常刻意地没有为斜体和粗体等内容或不同大小的内容包含单独的代码点,因为这些内容应该通过选择不同的字体来处理,而不是一组不同的 Unicode 代码点。因此,如果他们添加每个符号的镜像,那将是非常令人惊讶的。这将违背 Unicode 的理念。如果他们这样做了,那为什么不颠倒版本呢?为什么不旋转90度呢?等等,
所以我认为你的问题的简短答案是,这是不可能完成的。没有这样的 Unicode 字符。
Not sure what you're trying to accomplish. I think the simplest way to do this would be to get a set of images of all the letters and symbols, use flip them using any conventional graphics software -- PaintShopPro, PhotoShop, whatever -- save the images as a bunch of individual GIF or PNG files, and then retrieve the appropriate one when you need it.
If you really want to do the flipping within the Java program, I think the key is to:
Create a BufferedImage object
Call createGraphics on it to get a Graphics object.
Write the character or characters to this Graphics object using drawString
Then you can manipulate the image however you want using getRGB and setRGB. Basically you'd want to traverse the image from top to center swapping pixels from the top half to the bottom half.
I guess if you want it to work with any font, in many sizes, etc, you'd have to do it in a program.
Update
Based on your comment of Jan 30, it appears that you mean that you don't want to generate the reversed image yourself, but rather you want to find a reversed image among the Unicode character set. I'm afraid that, to the best of my knowledge, Unicode does not include a reverse image of every character. It includes a few that are symbols in their own right and that have specific meanings. For example, Unicode has a backwards capital E at U+2203, but if you look at other characters with nearby Unicode code points you'll see that they are various mathematical symbols. A backwards E is "in there" because it's a math symbol meaning "there exists", not because the inventors of Unicode are giving mirror images of every character.
I certainly don't have the complete Unicode code set memorized so I can't swear that there's no such set of characters in there somewhere, but I really doubt it. The point of Unicode was supposed to be to give a way to represent all the alphabets in the world and a robust set of commonly-used symbols. They very deliberately did NOT include separate code points for things like italic and bold, or for different sizes, because those things should be handled by selecting a different font, not a different set of Unicode code points. It would thus be very surprising if they added mirror images of every symbol. That would be contrary to the philosophy of Unicode. And if they did that, then why not upside down versions? Why not rotated 90 degrees? Etc etc.
So I think the short answer to your question is, It can't be done. There are no such Unicode characters.