2015-07-01 128 views
-2

我需要從相機捕捉圖像並將其存儲到imageView。Android。如何從相機捕捉圖像並將其保存到imageView?

Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(takePicture, 0); 

而且onActivityResult方法:

Uri selectedImage = imageReturnedIntent.getData(); 
mPhoto.setImageURI(selectedImage); 
+0

所以有什麼問題?請清楚你想要什麼 –

回答

1

只是嘗試這樣的:

此代碼捕獲來自相機的圖像和ImageView的顯示。

public class MainActivity extends ActionBarActivity { 
    ImageView imgFavorite; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     } 
    public void imageClick(View view){ 
     imgFavorite =(ImageView)findViewById(R.id.imageView1); 
     open(); 
    } 
    public void open(){ 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //IMAGE CAPTURE CODE 
     startActivityForResult(intent, 0); 
    } 
    protected void onActivityResult(int requestCode,int resultCode,Intent data){ 
    super.onActivityResult(requestCode,resultCode,data); 
     Bitmap bitmap=(Bitmap)data.getExtras().get("data"); 
     imgFavorite.setImageBitmap(bitmap); 
    } 
} 

XML文件:

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="14dp" 
    android:layout_marginTop="16dp" 
    android:contentDescription="@string/hello_world" 
    android:onClick="imageClick" 
    android:src="@drawable/camera_launcher" /> 
相關問題