首页 > 代码库 > android获取本地图片并显示图片
android获取本地图片并显示图片
import java.io.FileNotFoundException;import android.content.ContentResolver;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageView;import com.maikefengchao.daixu.R;public class WriteArticle_CompeterelayActivity extends BaseActivity { private ImageView im_upload_img; @Override public void initView(Bundle savedInstanceState){ setContentView(R.layout.view_write_competerelay); im_upload_img = (ImageView)findViewById(R.id.write_competerelay_cover_iv); } @Override protected void setListener() { im_upload_img.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); /* 开启Pictures画面Type设定为image */ intent.setType("image/*"); /* 使用Intent.ACTION_GET_CONTENT这个Action */ intent.setAction(Intent.ACTION_GET_CONTENT); /* 取得相片后返回本画面 */ startActivityForResult(intent, 1); } }); } @Override protected void processLogic(Bundle saveInstanceState) { } //获取本地图片 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri uri = data.getData(); Log.e("uri", uri.toString()); ContentResolver cr = this.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); ImageView imageView = (ImageView) findViewById(R.id.write_competerelay_cover_iv); /* 将Bitmap设定到ImageView */ imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(),e); } } super.onActivityResult(requestCode, resultCode, data); }}
android获取本地图片并显示图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。