Chinaunix

标题: Android开发返回拍摄的图片 [打印本页]

作者: 中关村村草    时间: 2011-11-26 10:47
标题: Android开发返回拍摄的图片
Android开发返回拍摄的图片






第一步
Java代码
  1. 1.try {   
  2. 2.     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);   
  3. 3.     startActivityForResult(intent, 0);   
  4. 4.  
  5. 5.} catch (ActivityNotFoundException e) {   
  6. 6.     // Do nothing for now   
  7. 7.}  
  8. try {
  9.      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  10.      startActivityForResult(intent, 0);

  11. } catch (ActivityNotFoundException e) {
  12.      // Do nothing for now
  13. }  
复制代码
第一步
Java代码
  1. 1.@Override  
  2. 2. protected void onActivityResult(int requestCode, int resultCode, Intent data) {   
  3. 3.  try {   
  4. 4.   if (requestCode != 0) {   
  5. 5.    return;   
  6. 6.   }   
  7. 7.   super.onActivityResult(requestCode, resultCode, data);   
  8. 8.   Bundle extras = data.getExtras();   
  9. 9.   Bitmap b = (Bitmap) extras.get("data");   
  10. 10.   //   
  11. 11.      
  12. 12.   //   
  13. 13.   ImageView a = (ImageView)findViewById(R.id.imageView1);   
  14. 14.   a.setImageBitmap(b);   
  15. 15.   //   
  16. 16.   /*  
  17. 17.    * 得到图片对图片处理...  
  18. 18.    */  
  19. 19.  } catch (Exception e) {   
  20. 20.   // TODO: handle exception   
  21. 21.   System.out.println(e.getMessage());   
  22. 22.  }   
  23. 23. }  
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2