How to resize text in java

I have seen that in photoshop text can be easily resized just by dragging them. How can we do the same thing in Java? Any idea on how to resize text in java? Added a snapshot of letter "A" resized in photoshop ![enter image description here][1] [1]: --- Please let me know what is wrong with this code? public class ResizeImage extends JFrame { public ResizeImage(){ JPanel panel = new JPanel(){ public void paintComponent(Graphics g) { // In your paint(Graphics g) method // Create a buffered image for use as text layer BufferedImage textLayer = new BufferedImage(240, 240, BufferedImage.TYPE_INT_RGB); // Get the graphics instance of the buffered image Graphics2D gBuffImg = textLayer.createGraphics(); // Draw the string gBuffImg.drawString("Hello World", 10, 10); // Rescale the string the way you want it gBuffImg.scale(200, 50); // Draw the buffered image on the output's graphics object g.drawImage(textLayer, 0, 0, null); gBuffImg.dispose(); } }; add(panel); } public static void main(String [] args){ ResizeImage frame = new ResizeImage(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setVisible(true); } }
You could render the font on a BufferedImage and then resize it the way you want it.

以上就是How to resize text in java的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准