Android uses Intent to call the system photo program to take pictures and solve the problem that the picture is too small
Intent it = newIntent(".IMAGE_CAPTURE"); startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);
After pressing the photo key, it will return to your activity, so your activity should be added to the onActivityResult method.
protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) { (requestCode, resultCode, data); try{ Bundle extras = (); Bitmap b = (Bitmap) ("data"); take = b; ImageView img = (ImageView)findViewById(); (take); }catch(Exception e){ } }
But in this way you will find that this bitmap is too small. It is obviously compressed. To return an uncompressed photo, you need to add parameters to the intent of the calling system photo program and specify the location of the image output.
Intent it = newIntent(".IMAGE_CAPTURE"); (MediaStore.EXTRA_OUTPUT, (newFile(F.SD_CARD_TEMP_PHOTO_PATH))); startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);
This is the return of the large picture.
protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) { (requestCode, resultCode, data); try{ ImageView img = (ImageView)findViewById(); take = ((F.SD_CARD_TEMP_PHOTO_PATH), 640); (take); imgflag = true; }catch(Exception e){ } }
Also note that the bitmap returned will be very large. You must recycle it after you use it, otherwise you will easily report Oom errors in the memory
public static Bitmap ResizeBitmap(Bitmap bitmap, intnewWidth) { intwidth = (); intheight = (); floattemp = ((float) height) / ((float) width); intnewHeight = (int) ((newWidth) * temp); floatscaleWidth = ((float) newWidth) / width; floatscaleHeight = ((float) newHeight) / height; Matrix matrix = newMatrix(); // resize the bit map (scaleWidth, scaleHeight); // (45); Bitmap resizedBitmap = (bitmap, 0, 0, width, height, matrix, true); (); return resizedBitmap; }
The above is the solution to the problem of Android calling the system to take photos. If you have any questions, please leave a message to discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!