2013-07-12 6 views
7

का उपयोग समझने के लिए मुझे पता है कि SO मैट्रिक्स प्रश्नों से भरा है, लेकिन मुझे कोई प्रश्न नहीं मिल रहा है जहां इसे पूरी तरह से समझाया गया है। मुझे लगता है कि किसी भी छवि दृश्य में एक मैट्रिक्स है जो स्केलिंग, घूर्णन और स्थिति के लिए ज़िम्मेदार है। लेकिन कारण है कि मैं एक छवि इस तरह की एक मैट्रिक्स का उपयोग कर बारी बारी से नहीं कर सकते हैं: क्यों मैं एक नया मैट्रिक्स हर बार जब मैं बनाने के लिएImageView मैट्रिक्स

ImageView img = (ImageView)findViewById(R.id.some_imageview); 
img.setScaleType(ScaleType.Matrix); 
Rect bounds = img.getDrawable.getBounds(); 
Matrix rotationMatrix = new Matrix(); 
rotationMatrix.postRotate(180f, bounds.width()/2, bounds.height()/2); 
img.setImageMatrix(rotationMatrix); 

:

ImageView img = (ImageView)findViewById(R.id.some_imageview); 
img.setScaleType(ScaleType.Matrix); 
Rect bounds = img.getDrawable.getBounds(); 
img.getImageMatrix().postRotate(180f, bounds.width()/2, bounds.height()/2); 

कई जवाब इस तरह यह करने के लिए सुझाव है घूमना चाहते हैं? इसके अलावा, अगर मैं दूसरे उदाहरण से मैट्रिक्स सेट करता हूं, तो क्यों यह फिर से घुमा नहीं रहा है (इसकी मूल डिग्री पर) यदि मैं rotationMatrix फिर से सेट करता हूं? अगर मैं मूल डिग्री प्राप्त करना चाहता हूं तो मैं एक सादा निर्मित मैट्रिक्स सेट कर सकता हूं। लेकिन फिर, मुझे समझ में नहीं आता क्यों

img.getImageMatrix().postRotate(180f, bounds.width()/2, bounds.height()/2); 

काम नहीं करेगा।

नोट: एक टिप्पणी

मैंने पूछा है क्यों मैं एक नया मैट्रिक्स हर, जो सवाल का तात्पर्य बनाने के लिए, क्यों की वजह से: मैं भी

संपादित कोई अंतर को देख बिना setRotate विधि की कोशिश की है मैं जगह में मैट्रिक्स का उपयोग नहीं कर सकता। इसके अलावा क्या मैं काम करने के लिए संदेह है कि यह था (जो वास्तव में नहीं होगा, भी):

ImageView img = (ImageView)findViewById(R.id.some_imageview); 
img.setScaleType(ScaleType.Matrix); 
Rect bounds = img.getDrawable.getBounds(); 
Matrix rotationMatrix = new Matrix(); 
rotationMatrix.postRotate(180f, bounds.width()/2, bounds.height()/2); 
img.setImageMatrix(rotationMatrix); 
//works until here. 

//Then after that successful call 

//assumed to get my Matrix back, which is rotated by 180 degrees 

Matrix matrix = img.getImageMatrix(); 
Rext bounds = img.getDrawable().getBounds() 
//rotate again at 90 degree. It should be now rotated 270 degrees (180 from before, plus 90 now) 
matrix.postRotate(90f, bounds.width()/2, bounds.height()/2); 
//unfortunately NO effect! 
img.setImageMatrix(matrix); 
+0

प्रलेखन कहता है कि आपको getImageMatrix द्वारा लौटाए गए मैट्रिक्स का उपयोग नहीं करना चाहिए। एक नज़र डालें [यहां] (http://developer.android.com/reference/android/widget/ImageView.html#getImageMatrix()) – Blackbelt

+0

@blackbelt मैंने एक स्पष्टीकरण के लिए कहा क्यों मुझे इस मैट्रिक्स का उपयोग नहीं करना चाहिए, कम से कम अगर यह शून्य नहीं है ..., विशेष रूप से अगर मैं इसे पहले सेट करता हूं ... –

+1

असल में आपने पूछा "मुझे हर बार एक नया मैट्रिक्स क्यों बनाना है जब मैं घूमना चाहता हूं?" – Blackbelt

उत्तर

1

source यह विधि setImageMatrix() मैट्रिक्स गणना लागू किया जाता है में की तरह दिखता है को देखते हुए। बाद में इस मैट्रिक्स का उपयोग करना (यानी गेटटर द्वारा प्राप्त करने के बाद) का कोई प्रभाव नहीं होगा यदि गणनाकर्ता विधि में गणना की जाती है।