- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
当要进分享照片功能时,点击一个
当要进分享照片功能时,点击一个按钮,然后进入图库选择照片,要进行这样的操作,改怎么完成呢,要解决2个问题:1、该如何进入图库2、改如何取得照片==================================================进入图库:? ? ? ? ? ? ? ? Intent intent = new Intent(); ?? ? ? ? ? ? ? ? intent.setType(image/*); ?? ? ? ? ? ? ? ? intent.setAction(Intent.ACTION_GET_CONTENT); ??? ? ? ? ? ? ? ? /* 取得相片后返回本画面 */ ?? ? ? ? ? ? ? ? startActivityForResult(intent, 1);?选取照片:? ? ? ? ? ? ? ?当点击照片后,会返回一个intent,那么,用getData();获得一个URI的数据,这个uri就是图片在数据库中的位置? ? ? ? ? ? ? ?然后该怎么通过这个uri操作,得到图片和路径呢??看下面源码吧====================================================最后详细的见源码public class StartActivityForResult extends Activity {? ? /** Called when the activity is first created. */? ? @Override? ? public void onCreate(Bundle savedInstanceState) {? ? ? ? super.onCreate(savedInstanceState);? ? ? ? setContentView(R.layout.main);? ? ? ??? ? ? ? Button button = (Button)findViewById(R.id.btn); ?? ? ? ? button.setText(选择图片); ?? ? ? ? button.setOnClickListener(new Button.OnClickListener(){ ?? ? ? ? ? ? @Override ?? ? ? ? ? ? public void onClick(View v) { ?? ? ? ? ? ? ? ?Intent intent = new Intent(); ?? ? ? ? ? ? ? ? intent.setType(image/*); ?? ? ? ? ? ? ? ? intent.setAction(Intent.ACTION_GET_CONTENT); ??? ? ? ? ? ? ? ? /* 取得相片后返回本画面 */ ?? ? ? ? ? ? ? ? startActivityForResult(intent, 1); ??? ? ? ? ? ? } ?? ? ? ? ? ? ??? ? ? ? }); ?? ? } ?? ? ??? ? @Override ?? ? protected void onActivityResult(int requestCode, int resultCode, Intent data) { ?? ? ? ? if (resultCode == RESULT_OK) { ?? ? ? ? ? ? Uri uri = data.getData(); ?? ? ? ? ? ? Log.e(uri, uri.toString());?? ? ? ? ? ? Log.e(uri, uri.getPath()); ?? ? ? ? ? ? ContentResolver cr = this.getContentResolver();??? ? ? ? ? ? //获得照片,并显示? ? ? ? ? ? try { ?? ? ? ? ? ? ? ? Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); ?? ? ? ? ? ? ? ? ImageView imageView = (ImageView) findViewById(R.id.iv); ?? ? ? ? ? ? ? ? /* 将Bitmap设定到ImageView */ ?? ? ? ? ? ? ? ? imageView.setImageBitmap(bitmap); ?? ? ? ? ? ? } catch (FileNotFoundException e) { ?? ? ? ? ? ?
文档评论(0)