概述
packagenet.viralpatel.android.imagegalleray;importandroid.app.Activity;importandroid.content.Intent;importandroid.database.Cursor;importandroid.graphics.BitmapFactory;importandroid.net.Uri;importandroid.os.Bundle;importandroid.provider.MediaStore;importandroid.view.View;importandroid.widget.Button;importandroid.widget.ImageView;public class ImageGalleryDemoActivity extendsActivity {private static int RESULT_LOAD_IMAGE = 1;
@Overridepublic voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonLoadImage=(Button) findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View arg0) {
Intent i= newIntent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
@Overrideprotected void onActivityResult(int requestCode, intresultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null !=data) {
Uri selectedImage=data.getData();
String[] filePathColumn={ MediaStore.Images.Media.DATA };
Cursor cursor=getContentResolver().query(selectedImage,
filePathColumn,null, null, null);
cursor.moveToFirst();int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath=cursor.getString(columnIndex);
cursor.close();
ImageView imageView=(ImageView) findViewById(R.id.imgView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
最后
以上就是淡定睫毛为你收集整理的android获取系统图片,android 从系统相册获取一张图片的全部内容,希望文章能够帮你解决android获取系统图片,android 从系统相册获取一张图片所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复