मुझे किसी छवि में ज़ूम इन करते समय व्यूपोर्ट की नई स्थिति की गणना करने की आवश्यकता है।JScrollPane - माउस स्थिति से संबंधित ज़ूम
यूआई बनाया गया है इस प्रकार है:
- ImagePanel छवि खींचता
- ImagePanelWrapper आसपास imagePanel
- jScrollPane एक JPanel रैपिंग है ImagePanelWrapper
जब में या ज़ूम शामिल बाहर, ImagePanel का ज़ूम कारक बदल दिया गया है और ImagePanel का पसंदीदा आकार पुन: गणना किया जा रहा है। इसलिए इस पैनल पर छवि चलता है, भले ही ImagePanel उसी व्यूपोर्ट बिंदु पर रहता है।
उपयोगकर्ता को CTRL को दबाकर और माउस व्हील का उपयोग करने पर निम्न विधियों को बुलाया जाता है। दिए गए बिंदु माउसहेल लिस्टनर द्वारा प्रदान किया गया कर्सर स्थान है। इन विधियों में कार्यक्षमता के साथ छवि ज़ूम इन या आउट होने पर पहले से ही उसी शीर्ष-बाएं-स्थिति पर रह रही है।
समस्या यह है कि मैं सिर्फ माउस के सापेक्ष स्थानांतरित करने के बारे में नहीं समझ सकता, उदाहरण के लिए Paint.NET। कोई विचार?
/**
*
*/
public void zoomOut(Point point) {
this.imagePanel.setZoom(this.imagePanel.getZoom() * 0.9f);
Point pos = this.getViewport().getViewPosition();
int newX = (int) (pos.x * 0.9f);
int newY = (int) (pos.y * 0.9f);
this.getViewport().setViewPosition(new Point(newX, newY));
this.imagePanel.revalidate();
this.imagePanel.repaint();
}
/**
*
*/
public void zoomIn(Point point) {
this.imagePanel.setZoom(this.imagePanel.getZoom() * 1.1f);
Point pos = this.getViewport().getViewPosition();
int newX = (int) (pos.x * 1.1f);
int newY = (int) (pos.y * 1.1f);
this.getViewport().setViewPosition(new Point(newX, newY));
this.imagePanel.revalidate();
this.imagePanel.repaint();
}
+1 बहुत बढ़िया, उत्तर। मैंने थोड़ी देर में देखा है। – max
आप सर एक बड़े धन्यवाद के लायक हैं :) – EyeSpy
मेरे पास एक समान सवाल है। मैं एक ही काम करने के लिए AffineTransform का उपयोग करने की कोशिश कर रहा हूं, और मुझे इस प्रश्न से गणित को लागू करने में कुछ परेशानी हो रही है। यदि आपको समय लगता है, तो क्या आप मेरी मदद कर सकते हैं? http://stackoverflow.com/questions/37509908/zoom-in-at-mouse-cursor – bigblind