2010-03-16 25 views
14

मैं कैमरा पूर्वावलोकनएंड्रॉइड - कैमरा पूर्वावलोकन

यह मेरा कोड है और यह कोई त्रुटि नहीं फेंकता है, लेकिन स्क्रीन अभी भी काला है। कोई विचार?

this.setContentView(R.layout.camerapreview);  
SurfaceView cameraSurface = (SurfaceView)findViewById(R.id.cpPreview); 
SurfaceHolder holder = cameraSurface.getHolder(); 
holder.addCallback(this); 
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
this.camera = Camera.open(); 
this.camera.setPreviewDisplay(holder); 
this.camera.startPreview(); 

camerapreview.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <SurfaceView 
     android:id="@+id/cpPreview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"> 

    </SurfaceView> 
</LinearLayout> 

उत्तर

46

आप पिछले तीन लाइनों बुला रहे हैं बहुत जल्दी। आपको setPreviewDisplay() पर कॉल करने से पहले सतह तैयार करने के लिए इंतजार करना होगा और आपको startPreview() पर कॉल करने से पहले सतह का आकार (surfaceChanged()) का इंतजार करना होगा। This project की आपको आवश्यकता है।

+0

यह बहुत अच्छा काम करता है। अतिरिक्त सवाल एंड्रॉइड 2.3 और 3.0 पर जब हम डिवाइस को घुमाते हैं तो पूर्वावलोकन को कम किया जाता है। क्या आपके पास इसका समाधान भी है? –

+1

@ नीलेशपावर: मुझे नहीं पता कि इस स्थिति में "skewed" से आपका क्या मतलब है। एफडब्ल्यूआईडब्ल्यू, मेरा वर्तमान कैमरा काम यहां है: https://github.com/commonsguy/cwac-camera – CommonsWare

+0

ओह वाह। आपके नए कोड से कैमरा-डेमोव 9 ने इस मुद्दे को हल किया !! मैं जो कुछ अलग कर रहा था उसका एक अंतर प्राप्त करूंगा और इसे हर किसी के लाभ के लिए यहां पोस्ट करूंगा। दुख की बात है कि इन क्षेत्रों में Google दस्तावेज अस्पष्ट है। –

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