2012-08-23 13 views
5

मैं एंड्रॉइड टैबलेट के लिए कोडिंग कर रहा हूं और मैं चाहता हूं कि मेरा ऐप surfaceView कैमरा पूर्वावलोकन के पोर्ट्रेट व्यू का उपयोग करे। यह डिफ़ॉल्ट रूप से परिदृश्य है, और मैंने निम्नलिखित दृश्य को चित्र दृश्य में घुमाने के लिए प्रयास किया:एंड्रॉइड-कैमरा को सतहदृश्य में पोर्ट्रेट में कैसे बदला जाए?

public void surfaceCreated(SurfaceHolder holder){ 
    // The Surface has been created, acquire the camera and tell it where to draw. 
    mCamera = Camera.open(); 
    Parameters params = mCamera.getParameters(); 
    // If we aren't landscape (the default), tell the camera we want portrait mode 
    if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE){ 
    params.set("orientation", "portrait"); // "landscape" 
    // And Rotate the final picture if possible 
    // This works on 2.0 and higher only 
    //params.setRotation(90); 
    // Use reflection to see if it exists and to call it so you can support older versions 
     try { 
     Method rotateSet = Camera.Parameters.class.getMethod("setRotation", new Class[] { Integer.TYPE }); 
     Object arguments[] = new Object[] { new Integer(270) }; 
     rotateSet.invoke(params, arguments); 
     } catch (NoSuchMethodException nsme) { 
     // Older Device 
     Log.v("CameraView","No Set Rotation"); 
     } catch (IllegalArgumentException e) { 
     Log.v("CameraView","Exception IllegalArgument"); 
     } catch (IllegalAccessException e) { 
     Log.v("CameraView","Illegal Access Exception"); 
     } catch (InvocationTargetException e) { 
     Log.v("CameraView","Invocation Target Exception"); 
     } 
    } 
    mCamera.setParameters(params); 
    try{ 
    mCamera.setPreviewDisplay(holder); 
    } catch (IOException exception) { 
    mCamera.release(); 
    mCamera = null; 
    } 
} 

लेकिन यह काम नहीं करता है। क्या कोई इसे ठीक कर सकता है?

public void surfaceCreated(SurfaceHolder holder) { 
    if (Build.VERSION.SDK_INT >= 8) mCamera.setDisplayOrientation(90); 
} 

कैमरा params.set("orientation"... सामान का उपयोग करना डिवाइस पर एक जैसी नहीं है और वास्तव में पूर्व एसडीके 8 भाषा है:

+0

ऑब्जेक्ट तर्कों के साथ भी प्रयास किया [] = नया ऑब्जेक्ट [] {नया इंटीजर (9 0)}; लेकिन फिर भी मैं इसे ठीक नहीं कर सका। –

+0

चूंकि आपको काम करने के लिए सतही दृश्य मिला है, तो क्या आप मुझे एक उदाहरण प्रदान कर सकते हैं। मुझे आईपैमेरा से अपने एंड्रॉइड में स्ट्रीम करने की ज़रूरत है और मैं सतही दृश्य का उपयोग करना चाहता हूं – Lily

उत्तर

7

आप शायद setDisplayOrientation समारोह का उपयोग करने के रूप में निम्न प्रकार चाहते हैं।

संबंधित मुद्दे