그래픽을 회전 하려는데 어떤 이유로 작동하지 않습니다. 나는 다른 포럼에서 연구를 많이했지만이 문제를 해결할 수없는 것 같습니다.그래픽을 회전하십시오.
이것은 내 프로그램 작업의 비트입니다.
- 파일을 가져옵니다.
- 는
- 가
Jlabel
이 완충 화상을 표시하는 패널, 상기 제bufferedimage.createGraohics();
에서의 Graphics2D를 생성 이미지 버퍼를 생성한다. 그런 다음 이미지에 텍스트를 쓰는 방법과 이미지를 저장하는 방법이 있습니다. 텍스트를 작성한 다음 저장하면 정상적으로 작동합니다. 이 사용
graphic2D.drawString("Hello, this is my test.",10,10);
나는이 업데이트 JLabel의 표시, 그래서 이미지에 텍스트를 볼 수 있습니다. 내가 생각하는 방법을 만들 경우
그러나 :
graphics2D.rotate(45);
나는 절대적으로 아무것도 변화를 참조하십시오.
이유를 알 수있는 사람이 있습니까?
public void actionPerformed(ActionEvent e){
graphic2D.rotate(4.5);
saveImage();
}
감사합니다, 당신이 다시 칠하고 텍스트를 렌더링하기 직전 회전 호출을 둘 필요가 있으므로
import java.io.File;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class EditorView implements ActionListener, ChangeListener{
JFrame editorFrame;
JPanel container = new JPanel();
JPanel toolbox = new JPanel();
JPanel editorPanel = new JPanel();
JScrollPane editorScrollPane;
File imageFile;
BufferedImage bi;
ImageIcon ii;
Graphics2D graphic2D;
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 10, 5);
public EditorView(File file){
this.imageFile = file;
try{
bi = ImageIO.read(imageFile);
}catch(Exception e){}
graphic2D = bi.createGraphics();
createAndShowGUI();
}
void createAndShowGUI(){
editorFrame = new JFrame("Editor");
editorFrame.setSize(1000,650);
container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS));
editorFrame.add(container);
toolbox.setMaximumSize(new Dimension(Integer.MAX_VALUE,50));
toolbox.setPreferredSize(new Dimension(Integer.MAX_VALUE,50));
toolbox.setLayout(new GridLayout(2,10));
JButton rotateLeftBtn = new JButton("Rotate Left");
toolbox.add(rotateLeftBtn);
rotateLeftBtn.addActionListener(this);
toolbox.add(new JButton("Save"));
toolbox.add(new JButton("Close"));
toolbox.add(new JButton("Freeform"));
toolbox.add(new JButton("Colour"));
toolbox.add(new JButton("Text"));
toolbox.add(new JButton("Square"));
toolbox.add(new JButton("Circle"));
toolbox.add(new JButton("Elipse"));
toolbox.add(new JButton("Rotate Right"));
slider.addChangeListener(this);
toolbox.add(slider);
container.add(toolbox);
editorScrollPane = new JScrollPane(new JLabel(new ImageIcon(bi)));
container.add(editorScrollPane);
editorFrame.setVisible(true);
editorFrame.validate();
container.validate();
editorPanel.validate();
drawLabel();
//editorScrollPane.repaint();
}
void drawLabel(){
graphic2D.rotate(1);
graphic2D.drawString("Hello, this is my test.",10,10);
}
void drawCircle(){
}
void saveImage(){
try{
ImageIO.write(bi,getFileExtension(), imageFile);
}catch(Exception e){}
}
String getFileExtension(){
int positionOfDot = imageFile.getName().lastIndexOf(".");
String returner = null;
if(positionOfDot !=-1){
returner = imageFile.getName().substring((positionOfDot+1), imageFile.getName().length());
}
System.out.println(returner);
return returner;
}
public void actionPerformed(ActionEvent e){
graphic2D.rotate(1);
saveImage();
}
public void stateChanged(ChangeEvent c){
graphic2D.scale(slider.getValue()/5, slider.getValue()/5);
editorScrollPane.repaint();
}
}
를 시도? –