Моя цель - добавить текст к изображениям и сохранить изображение. Я могу добавить текст на изображение.
Мой вопрос: как указать область для текста и как сделать его многострочным, чтобы данные не пересекали границу.
Код: -
public Test()
{
s = "Welcome TO Image Rendering";
s1="Title data";
s2="DescriptionA fast paced action thriller about a stunt driver.He finds himself a target for some dangerous men after he agrees to help his beautiful neighbour, Irene. Subtitles: Chinesedata";
Font f = new Font("Serif",Font.BOLD,22);
text = new JLabel("Welcome TO Image Rendering");
text.setFont(f);
AttributedString astr = new AttributedString(s);
astr.addAttribute(TextAttribute.FOREGROUND, Color.red, 0, 1);
MediaTracker mt = new MediaTracker(this);
image = Toolkit.getDefaultToolkit().createImage("c://Ci_Audio.jpg");
mt.addImage(image,0);
try{mt.waitForID(0);}catch(InterruptedException ie){}
int width = image.getWidth(null);
int height = image.getHeight(null);
BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bimg.createGraphics().drawImage(image, 0, 0, this);
bimg.getGraphics().setFont(f);
bimg.getGraphics().drawString(s,10,50);
bimg.getGraphics().drawString(s1,38,40);
bimg.getGraphics().drawString(s2,188,84);
img = new ImageIcon(bimg);
label = new JLabel(img);
p = new JPanel();
p.add(label);
getContentPane().add(p);
}
public static void main(String args[])
{
Test tt = new Test();
tt.setDefaultCloseOperation(EXIT_ON_CLOSE);
tt.setSize(360,305);
tt.setVisible(true);
}
}
Here String s2 Не подходит к экрану изображения. Заранее спасибо.