我怎样才能挽救意图相机拍摄的图像被用作个人资料图片? [英] How can i save the image taken from camera intent to be used as a profile image?
问题描述
在我的应用程序,用户可以从相机拍摄的图像并作为资料图片使用。一切正常,除了当用户离开应用程序,然后返回形象不存在了。所以,我怎么可以保存图像呆在那里,甚至当用户退出应用程序?
code相机意图:
意图cameraIntent =新意图(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,CAMERA_REQUEST);
和的onActivityResult
:
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == CAMERA_REQUEST){
。位图的照片=(位图)data.getExtras()获得(数据);
getLayoutInflater()膨胀(R.layout.custon_header,NULL);
ImageView的profimg =(ImageView的)findViewById(R.id.roundedimg);
profimg.setImageBitmap(照片);
可能有人请帮助我呢?
感谢
data.getExtras()获得(数据)。
只返回这将是对低质量的图像的缩略图。你必须指定在您的相机的意图所在的图像将被保存在一个位置:
文件OUTPUTFILE =新的文件(Environment.getExternalStorageDirectory()+/ myOutput.jpg);意图cameraIntent =新意图(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(Intent.EXTRA_OUTPUT,outputFile.getAbsolutePath());startActivityForResult(cameraIntent,CAMERA_REQUEST);
和你activityResult,只需使用OUTPUTFILE您的位图:
=位BitmapFactory.de codeFILE(outputFile.getAbsolutePath());
In my app the user can take an image from the camera and use as a profile picture. Everything works, except that when the user leaves the app and returns then the image isn't there anymore. So how can I save that image to stay there even when the user exits the app?
Code for camera intent:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
And onActivityResult
:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
getLayoutInflater().inflate(R.layout.custon_header,null);
ImageView profimg = (ImageView) findViewById(R.id.roundedimg);
profimg.setImageBitmap(photo);
Could someone please assist me with this?
Thanks
data.getExtras().get("data");
only returns the thumbnail of the image which would be on low quality. You have to specify on your camera intent a location where the image will be saved:
File outputFile = new File(Environment.getExternalStorageDirectory() +"/myOutput.jpg");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(Intent.EXTRA_OUTPUT,outputFile.getAbsolutePath());
startActivityForResult(cameraIntent, CAMERA_REQUEST);
and on your activityResult, simply use the outputfile for your bitmap:
bitmap = BitmapFactory.decodeFile(outputFile.getAbsolutePath());
这篇关于我怎样才能挽救意图相机拍摄的图像被用作个人资料图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!