2013-02-15 22 views
6

कैमरा पूर्वावलोकन में मैं एक आयताकार ओवरले (जो आयताकार फ्रेम की तरह अधिक होना चाहिए) कैसे जोड़ूं? मेरे आवेदन में एक बटन होता है जो क्लिक करने पर कैमरा खोलता है। मुझे उस कैमरे के पूर्वावलोकन में ओवरले की आवश्यकता है।कैमरा एप्लिकेशन में आयताकार ओवरले कैसे जोड़ें?

जावा फ़ाइल के लिए कोड है:

public class MainActivity extends Activity { 
    Button b; 
    Intent i; 
    Bitmap bmp; 
    final static int cameraData = 0; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     b = (Button) findViewById(R.id.button); 
     InputStream is = getResources().openRawResource(R.drawable.ic_launcher); 
     bmp = BitmapFactory.decodeStream(is); 
     b.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
      // TODO Auto-generated method stub 
      i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      startActivityForResult(i, cameraData); 

     } 
    }); 
} 
} 

लेआउट फ़ाइल इस प्रकार है:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_gravity="center" 
    android:text="click to take photo" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="click" 
    android:layout_gravity="center" /> 

</LinearLayout> 

उत्तर

4

आप SurfaceView वर्ग का विस्तार करके अपने खुद के पूर्वावलोकन बनाना होगा।

नीचे दिए गए लिंक को देखें जो आपकी मदद करता है।

Custom camera android

SurfaceView साथ FrameLayout लो बच्चे के रूप में अपनी आवश्यकताओं

+0

आयत कैसे आकर्षित किया? –

+0

आप कुछ छवि ले सकते हैं और इसे सतहदृश्य – koti

+0

ठीक से ऊपर रख सकते हैं .. तो आप सुझाव देते हैं कि मैंने आयताकार की छवि डाली है? क्या यह पारदर्शी होने जा रहा है? –

13

पहले एक सार्वजनिक कक्षा कि देखें फैली बनाने के अनुसार अनुकूलित। इसके ऑन ड्रा() विधि के अंदर, अपना आयत खींचें। उदाहरण के लिए:

public class Box extends View { 
    private Paint paint = new Paint(); 
    Box(Context context) { 
    super(context); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { // Override the onDraw() Method 
    super.onDraw(canvas); 

    paint.setStyle(Paint.Style.STROKE); 
    paint.setColor(Color.GREEN); 
    paint.setStrokeWidth(10); 

    //center 
    int x0 = canvas.getWidth()/2; 
    int y0 = canvas.getHeight()/2; 
    int dx = canvas.getHeight()/3; 
    int dy = canvas.getHeight()/3; 
    //draw guide box 
    canvas.drawRect(x0-dx, y0-dy, x0+dx, y0+dy, paint); 
    } 
} 

फिर, अपने कैमरा पूर्वावलोकन गतिविधि में, एक उदाहरण आपके बॉक्स वर्ग

Box box = new Box(this); 

फिर,

addContentView(box, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

एक हरे रंग आयत अपने कैमरे पर तैयार किया जाएगा है पूर्वावलोकन। सौभाग्य! यहां एक लिंक है जिसने मुझे Draw on camera preview

+0

आप केवल प्रतिभाशाली हैं! बहुत बहुत धन्यवाद और भगवान आशीर्वाद !!! – Vincy

+0

यह सही उत्तर होना चाहिए – graell