Widziałem, że w tekście programu Photoshop można łatwo zmienić rozmiar, przeciągając je. Jak możemy zrobić to samo w Javie? Masz pomysł na zmianę rozmiaru tekstu w java? Dodano migawkę literą „A” o zmienionym rozmiarze w photoshopieJak zmienić rozmiar tekstu w java
Proszę dać mi znać, co jest nie tak z tym kodem?
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);
}
}
Można wyrenderować czcionkę na "BufferedImage", a następnie zmienić jej rozmiar tak, jak chcesz. – Spoike
Czy to nie najwyższy czas, abyś *** przyjął *** odpowiedź na to pytanie lub wyjaśnił, dlaczego oferowane odpowiedzi nie były odpowiednie? –