Method 1:
This method will directly generate a photo from camera and return it to the application. However, the compressed image is returned, which is unclear.
try { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_WITH_DATA); } catch (ActivityNotFoundException e) { e.printStackTrace(); }
Bundle bundle = data.getExtras();bmp_selectedPhoto = (Bitmap) bundle.get("data");if (bmp_selectedPhoto != null) bmp_selectedPhoto.recycle();bmp_selectedPhoto = (Bitmap) data.getExtras().get("data");// int scale = ImageThumbnail.reckonThumbnail(bitMap.getWidth(),// bitMap.getHeight(), 500, 600);// bitMap = ImageThumbnail.PicZoom(bitMap,// (int) (bitMap.getWidth() / scale),// (int) (bitMap.getHeight() / scale));// bitMap = ThumbnailUtils.extractThumbnail(bitMap, 200, 200);if(bmp_selectedPhoto != null){ home_view.setBackground(new BitmapDrawable(getResources(), bmp_selectedPhoto));}
Method 2:
This method generates a temporary file on the SD card.
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);File appDir = new File(Environment.getExternalStorageDirectory()+ "/KengDieA");if (!appDir.exists()) {appDir.mkdir();}mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+ "/KengDieA/", "kengDiePic"+ String.valueOf(System.currentTimeMillis()) + ".jpg"));cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);try {cameraIntent.putExtra("return-data", true);startActivityForResult(cameraIntent, CAMERA_WITH_DATA);} catch (Exception e) {e.printStackTrace();}
Contentresolver Cr = This. getcontentresolver (); try {If (BMP _selectedphoto! = NULL) // if you do not release the image, the image will not have enough memory. decodestream (Cr. openinputstream (muri);} catch (filenotfoundexception e) {// todo auto-generated catch blocke. printstacktrace ();} home_view.setbackground (New bitmapdrawable (getresources (), BMP _selectedphoto ));