如何在调整图像大小时调整字体大小

如何在调整图像大小时调整字体大小

本文介绍了如何在调整图像大小时调整字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现的是...我在textpane中有一个文本,我将其转换为BufferedImage并通过使用鼠标拖动来调整图像大小.现在,如果要编辑文本,请单击该图像,该图像将隐藏该图像并显示来自文本窗格的文本.

What I am trying to achieve is that... I have a text in textpane which I am converting to BufferedImage and resizing the size of the image by dragging it with mouse. Now If I want to edit the text, I am clicking on the image which hides the image and shows the text from textpane.

我的问题是文本窗格中文本的大小没有调整大小(增加/减小),因为调整大小是在图像而不是文本上进行的.那么,当我调整包含文本的图像的大小时,如何更改字体大小?

My problem is the size of the text in textpane is not resized(increased/decreased) as resize was done on image and not on text. So how do I change the font size as and when I resize the image containg text?

推荐答案

您可以通过使用AffineTransform派生基本字体来调整字体大小.基本上,您将需要维护对用户开始使用的基本字体的引用.必要时,您可以通过以适当的比例提供AffineTransform来派生新的字体实例,并将其应用于文本窗格

You can adjust the font size by deriving the base font with a AffineTransform. Basically, you will need to maintain a reference to the base font that the user started with. When you need to, you would derive a new font instance by suppling a AffineTransform with the appropriate scale and apply that to the text pane

请参见 Font#deriveFont(AffineTransform trans) 了解更多详情

See Font#deriveFont(AffineTransform trans) for more details

这篇关于如何在调整图像大小时调整字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:34