The following code calls the system photo program,
12 |
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,
12345678910111213 |
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.
123 |
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.
123456789101112 |
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.
1234567891011121314151617 |
Publicstaticbitmap 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 MapMatrix. postscale (scalewidth, scaleheight );// Matrix. postrotate (45 );Bitmap resizedbitmap = bitmap. createbitmap (bitmap, 0, 0, width, height, matrix, true );Bitmap. Recycle ();Returnresizedbitmap;} |
|