में एक छवि घुमाएं मैं एक छवि को घुमाएगा। मेरे पास JInternalFrame
है जिसमें JLabel
है। लेबल में छवि है। छवि घूर्णन करने के बाद, मुझे आंतरिक फ्रेम का आकार बदलना होगा। कोड जो मैंने वर्तमान में छवि को घुमाया है, लेकिन छवि के किनारों के चारों ओर काला है और यह केंद्रित है। इसे ठीक करने के लिए कोई सुझाव?जावा
public void rotateIcon(int angle)
{
int w = theLabel.getIcon().getIconWidth();
int h = theLabel.getIcon().getIconHeight();
int type = BufferedImage.TYPE_INT_RGB; // other options, see api
BufferedImage DaImage = new BufferedImage(h, w, type);
Graphics2D g2 = DaImage.createGraphics();
double x = (h - w)/2.0;
double y = (w - h)/2.0;
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.toRadians(angle), w/2.0, h/2.0);
g2.drawImage(new ImageIcon(getData()).getImage(), at, theLabel);
g2.dispose();
theLabel.setIcon(new ImageIcon(DaImage));
this.setSize(DaImage.getWidth(),DaImage.getHeight()); //resize the frame
}
से सामान्य तौर पर, एक छवि घूर्णन चौड़ाई और ऊंचाई (एक्स और वाई अक्ष के सापेक्ष) बदल जाता है। मुझे लगता है कि यह "केंद्रित बंद" होने में योगदान दे रहा है। मुझे इसे नए आकार और इसके लिए लेखांकन की गणना करके हल करना पड़ा है। काले किनारों के लिए, यह एक बहुत ही आम मामला है जहां घूर्णन कार्य अल्फा चैनल के साथ काम नहीं कर रहा है। हो सकता है कि यह स्थिति के लिए मदद करेगा: http://stackoverflow.com/questions/2056338/calculating-the-center-of-rotation-after-translation – Jere
यह भी देखें http://stackoverflow.com/questions/3420651 – trashgod