2013-07-11 18 views

回答

0

我已經使用這種佈局對於

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/layoutCam"> 

<FrameLayout 
    android:id="@+id/preview" 
    android:layout_weight="1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
</FrameLayout> 

<ImageView 
    android:id="@+id/imgHole" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:layout_gravity="center"/> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:text="Take Snap" 
    android:id="@+id/btnTakeSnap"/> 
</FrameLayout> 

和Java代碼是

public void onClick(View v) 
     { 
      preview.camera.takePicture(shutterCallback, rawCallback, postViewCallback, jpegCallback); 
      chal(); 
     } 

private boolean chal() 
     { 
      buttonTakeSnap.setVisibility(View.INVISIBLE); 
      View v1 = camView.getChildAt(1); 
      v1.setDrawingCacheEnabled(true); 
      v1.buildDrawingCache(); 
      bmp = v1.getDrawingCache(); 
      v1.setDrawingCacheEnabled(true); 
      buttonTakeSnap.setVisibility(View.VISIBLE); 
      Toast.makeText(this, "Akhtitaam", Toast.LENGTH_SHORT).show(); 
      return true; 
     } 

使用此代碼我得到兩個位圖從一個CHAL();方法,第二個來自jpegCallBack();方法現在你可以把一個相同的佈局,這些位圖重疊並捕捉這一觀點

使用此代碼

使用此方法來捕獲意見

public static Bitmap loadBitmapFromView(View v) 
{ 
    Paint drawPaint = new Paint(Paint.FILTER_BITMAP_FLAG); 
    drawPaint.setAntiAlias(false); 
    drawPaint.setFilterBitmap(false); 
    Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); 
    Canvas c = new Canvas(b); 
    c.drawBitmap(b, 0, 0, drawPaint); 
    v.draw(c); 
    return b; 
} 

通過相機的表面觀像參數這

View view=(YourParentLayout) findViewById(R.id.YourParentLayout); 
loadBitmapFromView(view);  
+0

您好但它會顯示唯一的用戶界面,但沒有攝像頭,我想捕捉UI(花)和cameraview simultaneouly –

+0

我覺得你的相機和鮮花都是在相同的佈局,所以請通過你的父母的佈局作爲查看 – farrukh

+0

是的,我嘗試了相同的,仍然沒有運氣,實際上surfaceview顯示黑色screen.and我能夠看到只有花。 –

相關問題