To solve the problem that the system camera program is called through Intent and the image returned is too small, intent calls
Intent it = newIntent("android.media.action.IMAGE_CAPTURE");startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);
After you press the photo key, your activity will be returned. Therefore, you must add a processing method to the onActivityResult method,
protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try{ Bundle extras = data.getExtras(); Bitmap b = (Bitmap) extras.get("data"); take = b; ImageView img = (ImageView)findViewById(R.id.image); img.setImageBitmap(take); }catch(Exception e){ }}
However, you will find that the bitmap is too small. Obviously, the image has been compressed. to return an uncompressed image, you must add a parameter to the System camera program intent to specify the image output position.
Intent it = newIntent("android.media.action.IMAGE_CAPTURE");it.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(newFile(F.SD_CARD_TEMP_PHOTO_PATH)));startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);
In this case, the large image is returned.
protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try{ ImageView img = (ImageView)findViewById(R.id.image); take = U.ResizeBitmap(U.getBitmapForFile(F.SD_CARD_TEMP_PHOTO_PATH), 640); img.setImageBitmap(take); imgflag = true; }catch(Exception e){ }}
Note that the returned bitmap will be very large. You need to recycle it after use, or you will easily report an oom error in the memory.
public static Bitmap ResizeBitmap(Bitmap bitmap, intnewWidth) { intwidth = bitmap.getWidth(); intheight = bitmap.getHeight(); floattemp = ((float) height) / ((float) width); intnewHeight = (int) ((newWidth) * temp); floatscaleWidth = ((float) newWidth) / width; floatscaleHeight = ((float) newHeight) / height; Matrix matrix = newMatrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // matrix.postRotate(45); Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); bitmap.recycle(); return resizedBitmap;}